Commit Graph

151 Commits

Author SHA1 Message Date
Michael J. Sullivan
65863bebf4 make __class__ refer to the current object's class (#2480)
This is just a direct rehash of #1549.
2018-09-25 18:04:37 -07:00
Michael J. Sullivan
4f4a025409 Remove tuple's __init__ method (#2467)
The __new__ method should suffice, and having both interferes with providing
a __new__ in namedtuples, which we want to do to fix
https://github.com/python/mypy/issues/1279.
2018-09-18 20:01:14 -07:00
Zac Hatfield-Dodds
6afa610191 memoryview is a context manager (#2442)
Since Python 3.2, __enter__ returns self and __exit__ calls self.release()
2018-09-11 14:13:38 +02:00
David Euresti
4e40b035c8 BaseException does not take keyword arguments (#2348)
Fixes #2344
2018-07-27 13:28:43 -07:00
Omar Sandoval
42db5ad4f7 Add missing int.__index__() signature (#2335)
This has been present since Python 2.5.
2018-07-16 15:30:06 -07:00
Sebastian Rittau
95eff73ab2 Drop Python 3.3 support from several stubs (#2265)
* Drop Python 3.3 support from several stubs

* Revert wrong socketserver changes
2018-06-20 16:49:47 -07:00
Jason Fried
451deba4ef memoryview type information inconsistent with runtime behavior (#2230)
memoryview type information inconsistent with documentation of typing module. 

`memoryview` should be a ByteString like the docs say. 
`memoryview.__init__` does not accept str, and instead of a union it should just accept ByteString. 
`memoryview.__iter__` returns an Iterator[int] not bytes.
2018-06-15 07:51:56 -07:00
Jelle Zijlstra
f5a74fd5da remove Optional from type of __slots__ (#2128)
Fixes #1853
2018-06-11 14:29:11 -07:00
Froger David
ffba2ea87a compile builtin accept PathLike (#2200) 2018-06-05 14:02:46 -07:00
Michael Lee
97d9f2eb2c Ensures overloads are ordered from narrow to broad (#2138)
This commit reorders any overloads where the first overload was
"shadowing" the second, preventing it from ever being matched by type
checkers that work by selecting the first matching overload alternative.

For example, the first overload alternative below is strictly broader
then the second, preventing it from ever being selected:

    class Parent: pass
    class Child(Parent): pass

    @overload
    def foo(x: *int) -> Parent: ...
    @overload
    def foo(x: int, y: int) -> Child: ...

The correct thing to do is to either delete the second overload or
rearrange them to look like this:

    @overload
    def foo(x: int, y: int) -> Child: ...
    @overload
    def foo(x: *int) -> Parent: ...

Rationale: I'm currently [working on a proposal][0] that would amend
PEP 484 to (a) mandate type checkers check overloads in order and
(b) prohibit overloads where an earlier alternative completely shadows
a later one.

  [0]: https://github.com/python/typing/issues/253#issuecomment-389262904

This would prohibit overloads that look like the example below, where
the first alternative completely shadows the second.

I figured it would be a good idea to make these changes ahead of time:
if my proposal is accepted, it'd make the transition smoother. If not,
this is hopefully a relatively harmless change.

Note: I think some of these overloads could be simplified (e.g.
`reversed(...)`), but I mostly stuck with rearranging them in case I was
wrong. The only overload I actually changed was `hmac.compare_digest` --
I believe the Python 2 version actually accepts unicode.
2018-05-17 09:45:33 -04:00
Jelle Zijlstra
537b97ed39 add bytearray.copy to Python 3 (#2133)
Fixes #1715.

2.7's bytearray doesn't have it.
2018-05-15 14:33:24 -04:00
Omar Sandoval
0a30d22f0d Fix Python 3 round() signature (#2107)
In Python 3, the ndigits argument of round() defaults to None. If
ndigits is excluded or explicitly None, the result is always an int. If
ndigits is not None, the result should be the same type as the number.

$ cat test.py
from fractions import Fraction

print(type(round(0.1)))
print(type(round(0.1, None)))
print(type(round(0.1, 0)))

print(type(round(Fraction(1, 10))))
print(type(round(Fraction(1, 10), None)))
print(type(round(Fraction(1, 10), 0)))
$ python3 ./test.py
<class 'int'>
<class 'int'>
<class 'float'>
<class 'int'>
<class 'int'>
<class 'fractions.Fraction'>

Update the signatures to allow for an ndigits of None.
2018-05-11 14:02:09 -04:00
Salvo 'LtWorf' Tomaselli
d289c20260 Add __new__ to tuple stub (#2092)
Closes: #2091

Apply suggestions from https://github.com/python/typeshed/pull/2092
2018-05-09 16:30:58 -07:00
Semyon Proshev
5223b26ec8 Add __round__ to int and float in Python 3 (#2061) 2018-04-17 14:25:04 -07:00
Alan Du
bd26c7bf84 Add __complex__ to complex (#2004)
* Add __complex__ to complex

complex SupportsComplex!

* Allow constructing complex from SupportsComplex
2018-04-03 07:14:52 -07:00
Matt Gilson
8e3182dafa dict.fromkeys supports arbitrary iterables. (#2012)
This should fix #1529.
2018-04-03 07:12:04 -07:00
Jelle Zijlstra
103056eecf fix some TODOs (#1994)
- Made deque.maxlen read-only
- We don't support 3.2, so we don't care about signature changes in it
- There don't seem to be any missing set operations (I compared the dir() of this class to that of builtins.set)
2018-03-28 18:40:13 -07:00
Eric Wieser
6cf1ec9654 Mark all dunder attributes of BaseException as Optional (#1992)
All of these properties can be set to `None`.

Also updates `with_traceback` to only accept the values which can be stored in `__traceback__`
2018-03-28 07:55:10 -07:00
Semyon Proshev
ac70fdc614 Overloads for map (#1990) 2018-03-27 10:05:59 -07:00
rchen152
38dc8f5a6a Switch usages of mypy_extensions.NoReturn over to typing.NoReturn. (#1942)
* Change mypy_extensions.NoReturn to typing.NoReturn everywhere.
2018-03-05 12:42:29 -08:00
Ivan Levkivskyi
7ae2f25216 Fix some problems introduced by recent commits. (#1905) 2018-02-20 13:34:48 -08:00
David Euresti
8ecb74012a Add __divmod__ to numeric types (#1900)
Helps with #1889
2018-02-18 16:59:12 -08:00
Marti Raudsepp
d288f443b9 Merge {IO,Environment,Windows}Error into OSError for Python 3.3+ (#1852)
Starting with Python 3.3, IOError, EnvironmentError and WindowsError are
aliases for OSError, which has all the attributes.

Reference:
* https://docs.python.org/3/library/exceptions.html#OSError
* https://www.python.org/dev/peps/pep-3151/

* OSError: Drop Python <3.3 compatibility
* Use Any instead of Union for filename/filename2 type, per GvR comment
See: https://github.com/python/mypy/pull/4541
2018-02-14 16:33:56 +00:00
George King
1533602779 filter function: make the callable of the first overload non-optional so that mypy is able to select the second overload for the case. (#1855) 2018-02-05 10:50:40 -08:00
Marti Raudsepp
15f07f5d03 Add ImportError attributes name, path for Python 3.3+ (#1849)
Reference: https://docs.python.org/3/library/exceptions.html#ImportError
2018-02-01 07:38:26 -08:00
Semyon Proshev
3e00a8f8e1 PEP 553 and PEP 564 (#1846)
* Add `breakpoint` to builtins (PEP 553)

* Add new `time` functions (PEP 564)
2018-01-31 16:51:25 -08:00
Anthony Sottile
03044212d4 Add typings for bool __{r,}{and,or,xor}__ (#1795) 2017-12-20 21:04:55 -08:00
Ivan Levkivskyi
ec2cb8e44f Convert selected ABCs to Protocols (#1220) 2017-11-19 08:52:16 -08:00
Jelle Zijlstra
324f1761f4 Change more defaults to ... (#1727) 2017-11-09 10:32:17 -08:00
Jelle Zijlstra
54dd6ba27c Change numerous default values to ... (#1722)
This is the convention, and some default values (e.g. strings) apparently
break pytype.
2017-11-09 06:28:40 -08:00
Sebastian Steenbuck
2551b76bde Replace default strings ' ' with ... (#1721)
This fixes a problem with pytype.
2017-11-08 08:49:54 -08:00
FichteFoll
f933b9384c Refine str.maketrans and str.translate (#1613)
str.translate requires a Mapping or Sequence (in essence, anything
with __getitem__), not a Dict.

str.maketrans in the one-argument form only converts character string
keys to their unicode ordinal, leaving any of the values untouched.
This mapping may use both integers or strings as keys at the same time.

str.maketrans in the multi-argument form returns a dict with any of the
values str, int or None, as recognized by str.translate.
2017-11-07 18:55:05 -08:00
anentropic
05f527c089 BaseException.__init__ accepts **kwargs (#1704) 2017-11-03 23:10:34 -07:00
Travis Parker
355f30cc70 Correct return type of sum() builtin (#1582)
`sum([])` always returns the integer 0.
2017-10-04 21:42:35 -07:00
Jelle Zijlstra
78587dc895 Revert "make __class__ refer to the current object's class (#1549)" (#1632)
This reverts commit 1a164b630c.

Reverts python/typeshed#1549.

See Guido's comments in the original PR.
2017-09-29 11:37:54 -07:00
Jelle Zijlstra
1a164b630c make __class__ refer to the current object's class (#1549)
Fixes python/mypy#3061
2017-09-27 18:11:59 -07:00
Luka Sterbic
1f867d8ab8 Fix int(Union[str, int]) (#1551) 2017-09-23 09:59:15 -04:00
Melvyn Sopacua
ebed7c2ecb Codeobject support (#1606) 2017-09-22 06:54:58 -07:00
Guido van Rossum
76685480e0 Misc fixes found by running mypy against Dropbox internal codebase "C". (#1575) 2017-08-25 20:34:13 -07:00
Garrett
975c9a09ef Add range attributes (#1561) 2017-08-22 06:11:55 -07:00
Svyatoslav Ilinskiy
4491e415f9 Make operations on set take AbstractSet[object] (#1533)
Previously they were `AbstractSet[Any]`
2017-08-11 17:17:47 -07:00
Jelle Zijlstra
d60f26c448 add object.__dir__ in Python 3 (#1532)
In Python 3 (but not Python 2), `object().__dir__()` works and returns a list of strings.

This is relevant when implementing a custom `__dir__` that invokes `super().__dir__()`.
2017-08-07 19:29:13 -07:00
Svyatoslav Ilinskiy
8ac0694056 Make functions any and all accept Iterable[object] (#1531)
Previously, they were accepting `Iterable`, which expanded to `Iterable[Any]`.
2017-08-07 17:13:43 -06:00
Svyatoslav Ilinskiy
aa68403230 Make BaseException's init accept object instead of Any (#1518) 2017-08-03 12:57:59 -07:00
Jelle Zijlstra
16aa0651ae Revert "Add __new__ to str and int stubs in both Pythons. (#1352)" (#1466)
This reverts commit fed4e03e53.
2017-07-06 14:21:54 -07:00
Guido van Rossum
350563223f Add Optional[] for all remaining cases of x: <type> = None (#1424)
* Final round of adding Optional[] to type of arguments with default = None
* Update Travis to use --no-implicit-optionals and clarify CONTRIBUTING.md
2017-06-21 10:50:21 -07:00
Semyon Proshev
fed4e03e53 Add __new__ to str and int stubs in both Pythons. (#1352)
* Update default values to `...` in `__init__` and `__new__` in `int` and `str`.
* Add `__new__` to `enum.IntEnum` to override inherited `__new__`.
* Add `type: ignore` comment to `IntEnum`
2017-06-12 20:53:32 -07:00
Semyon Proshev
5db571a8f3 Update typing.MutableMapping.update stubs to allow keyword-only arguments (#1370) 2017-05-30 21:44:10 -07:00
Matthias Kramm
8d8a34cb83 Patch from @sfreilich: make itertools.ifilter predicate parameter Optional (#1257)
From Samuel Freilich:
In Python 2, the predicate parameter in itertools.ifilter and
itertools.ifilterfalse can be None, indicating that true or false values
should be retained (functionally equivalent to passing "bool" as the
predicate). In Python 3, filter and itertools.filterfalse have
the same behavior.
2017-05-09 17:50:11 -07:00
Matthew Page
0e21ac9892 Add stub for string.casefold
Exists in 3.3+
2017-05-05 11:11:25 -07:00