Commit Graph
539 Commits
Author SHA1 Message Date
Diego Elio PettenòandJelle Zijlstra 99a6fb3108 Add the (deprecated) assertDictContainsSubset() to TestCase. (#3437)
Until this is removed from the standard library, it probably should stay in the typing.

Also update both 2 and 3 definitions to use Mapping[Any, Any], rather than Dict[Any, Any].
2019-11-04 08:10:45 -08:00
Diego Elio PettenòandJelle Zijlstra 7e27bf6bde Allow datetime() with a delta=timedelta() in assert(Not)AlmostEqual(s). (#3426)
While the documentation does not seem to make this particularly
obvious, it is allowed.
2019-11-02 22:35:09 -07:00
Rune TynanandJelle Zijlstra b112c20dad Copyreg stubs (#3387) 2019-10-29 19:52:05 -07:00
Sebastian RittauandJelle Zijlstra 87d7dd3d95 Fix annotations with literal values (#3411) 2019-10-28 06:59:28 -07:00
Alexander SchlarbandSebastian Rittau 124111534a Add the memoryview.release method (#3405) 2019-10-25 14:29:44 +02:00
Vasily ZakharovandSebastian Rittau 4f13e710c3 Added stub for urllib.proxy_bypass() (#3396) 2019-10-22 19:10:50 +02:00
Sebastian RittauandGitHub ec7960a8cb Convert namedtuples to class syntax (#3321) 2019-10-20 10:37:33 +02:00
Rebecca ChenandSebastian Rittau ffd73b3e8e Add shlex.shlex.next in Python 2. (#3389)
shlex.shlex should match the Iterator protocol, for which it needs both
`__iter__` and `__next__` (`next` in Python 2) defined.
2019-10-18 23:13:38 +02:00
Eric N. Vander WeeleandSebastian Rittau 966f8d24e6 Revert __import__ function annotation to return type back to Any (#3383)
From python/mypy#7582.

This partially reverts back the change in
0ee7c3c38b to have `__import__` return
`Any` instead of `ModuleType`.
2019-10-18 00:10:41 +02:00
Sebastian RittauandGitHub b969ead0ce Reorder memoryview.__setitem__ overloads (#3365)
Necessary for python/mypy#7717
2019-10-15 14:14:48 +02:00
Sebastian RittauandJelle Zijlstra 950f391704 Remove unnecessary __all__ annotations (#3357) 2019-10-13 16:22:03 -07:00
Sebastian RittauandGitHub de26a3d109 Remove raise statements from function bodies (#3355)
While it may eventually be useful to mark the exceptions that can be
raised from a function or method, the semantics are currently undefined
and unclear.
2019-10-13 21:51:43 +02:00
Utkarsh GuptaandSebastian Rittau 91b72d49c7 typing.pyi: Remove verbose and rename from NamedTuple (#3352)
Closes #3235
2019-10-12 21:27:50 +02:00
Florian BruhinandJelle Zijlstra 9b0922166a Allow callables in _SourceObjectType (Python 2) (#3338)
This is important because mypy doesn't generally think functions are compatible with `FunctionType`, so `inspect.getsource` on arbitrary functions is rejected by the current annotations.
2019-10-10 20:51:56 -07:00
Sebastian RittauandJelle Zijlstra 8a7d61741d Python3.8 additions and changes (#3337)
* Add as_integer_ratio() to a few types

* Add dirs_exist_ok to copytree()

* int, float, complex accept __index__ args

Also fix complex.__init__ argument names

* Add __reversed__ to dict et al.

* Python 3.8 date(time) arithmetic fixes

* Add CodeType.replace()
2019-10-10 20:51:27 -07:00
Russ AllberyandSebastian Rittau f0ccb325aa Mark some urllib.parse return fields optional (#3332)
Per the urllib.parse documentation, username, password, hostname,
and port will be set to None if not set in the parsed URL.  The
same is true for urlparse in Python 2 according to its documentation.
2019-10-09 19:38:59 +02:00
Sebastian RittauandJelle Zijlstra 07c8675ba5 Remove unused # type: ignore comments (#3325) 2019-10-09 10:27:18 -07:00
wouter bolsterleeandSebastian Rittau 824e94a933 Make 2-arg iter() retrun type match passed callable's return type (#3326)
This is a continuation of #3291, which was the initial fix for #3201.

The 2-arg version of iter() turns a callable into an iterator. The
changes made in #3291 introduce an Any return type for both the
callable's return type and the iterator's type, while in reality the
return type of the function is always the same as the iterator's type.
2019-10-09 08:44:41 +02:00
Sebastian RittauandJelle Zijlstra 256b3ce8ab Remove a bunch of unused imports (#3323) 2019-10-08 07:59:32 -07:00
Rune TynanandSebastian Rittau 7710e925ca Add data to UserList class, fix UserDict.data type (#3316) 2019-10-07 17:05:19 +02:00
sinancepelandJelle Zijlstra cd418e9546 introduce __floor__ and __ceil__ for int in Python 3 (#3306) 2019-10-04 19:16:32 -07:00
Rebecca ChenandGitHub 90aa27b54a Fix the signature of IOBase._checkClosed(). (#3305)
* In Python 2, the optional `msg` argument was missing.
* In Python 3, the method was missing altogether.

Reference:
https://github.com/python/cpython/blob/2.7/Lib/_pyio.py#L423
https://github.com/python/cpython/blob/3.6/Lib/_pyio.py#L443
2019-10-04 14:53:48 -07:00
Utkarsh GuptaandSebastian Rittau fa571fb224 builtins.pyi: Use two type vars (#3291)
Fixes: #3201
2019-10-04 00:15:41 +02:00
Sebastian RittauandJelle Zijlstra c32e1e2280 Enable --disallow-any-generics for stubs (#3288) 2019-10-01 05:31:34 -07:00
Eric TrautandJelle Zijlstra 468d13a205 Modified __add__ method in tuple class (#3252)
Modified __add__ method in tuple class to allow it to accept tuples with different generic parameter types. This allows, for example:
a = (1, )
b = a + (2.4, )
2019-09-30 12:42:40 +02:00
Guido van RossumandGitHub b336182b69 Fix some errors with --disallow-any-generics (#3276)
See #3267. Covers all of stdlib/2and3.
2019-09-29 09:15:27 -07:00
Árni Már JónssonandSebastian Rittau e0cc8bdafb inspect.Traceback/FrameInfo index/code_context attributes now Optional[] (#3265)
Resolves #3264
2019-09-26 17:13:00 +02:00
Rebecca ChenandSebastian Rittau 3f8c2169d1 Define listdir in posix and import it in os. (#3258) 2019-09-23 23:41:05 +02:00
sinancepelandSebastian Rittau 01b7002a89 Introduce explicit __str__ and __repr__ for Exceptions (#3247) 2019-09-23 18:25:49 +02:00
Rebecca ChenandSebastian Rittau 9488b58fb3 Copy a better definition of abstractmethod from 3/abc to 2/abc. (#3242) 2019-09-18 11:04:53 +02:00
Benjamin PetersonandSebastian Rittau 3fc8aec425 Allow passing str to Python 2's bytearray.extend. (#3223) 2019-09-04 23:24:58 +02:00
Sebastian RittauandGitHub efb4af0108 Mark some types as non-hashable (#3219)
Based on @JelleZijlstra's PR #2221.

Fixes #2148
2019-09-04 17:38:09 +02:00
BouteillebleuandSebastian Rittau d5a918de7b Add stubs for CGIHTTPServer (#3196)
This commit adds:
* Stubs for CGIHTTPServer in the Python 2 standard library, as requested in #1147.
* Stubs for six.moves.CGIHTTPServer in Python 2, as requested in #22.
2019-08-19 15:34:29 +02:00
Ran BenitaandJelle Zijlstra b2cd972b17 builtins: int.__pow__ can take a modulo argument (#3192)
See:
https://docs.python.org/3/reference/datamodel.html#object.__pow__
https://docs.python.org/3/library/functions.html#pow
2019-08-17 07:23:53 -07:00
Ran BenitaandJelle Zijlstra c7417e8b3f builtins,numbers: harmonize float.__round__ and Real.__round__ (#3193)
See:
https://docs.python.org/3/reference/datamodel.html#object.__round__
https://docs.python.org/3/library/functions.html#round
2019-08-17 07:23:04 -07:00
Ran BenitaandJelle Zijlstra c0625d3280 builtins: add __trunc__ to int and float (#3194)
See:
https://docs.python.org/3/reference/datamodel.html#object.__trunc__

It also works on Python 2.7.
2019-08-17 07:22:03 -07:00
Michael LeeandJelle Zijlstra b294782183 Make most contextmanager __exit__ signatures return Optional[bool] (#3179)
This pull request is a follow-up to https://github.com/python/mypy/issues/7214.

In short, within that mypy issue, we found it would be helpful to
determine between contextmanagers that can "swallow" exceptions vs ones
that can't. This helps prevent some false positive when using flags that
analyze control flow such as `--warn-unreachable`. To do this,
Jelle proposed assuming that only contextmanagers where the `__exit__`
returns `bool` are assumed to swallow exceptions.

This unfortunately required the following typeshed changes:

1. The typing.IO, threading.Lock, and concurrent.futures.Executor
   were all modified so `__exit__` returns `Optional[None]` instead
   of None -- along with all of their subclasses.

   I believe these three types are meant to be subclassed, so I felt
   picking the more general type was correct.

2. There were also a few concrete types (e.g. see socketserver,
   subprocess, ftplib...) that I modified to return `None` -- I checked
   the source code, and these all seem to return None (and don't appear
   to be meant to be subclassable).

3. contextlib.suppress was changed to return bool. I also double-checked
   the unittest modules and modified a subset of those contextmanagers,
   leaving ones like `_AssertRaisesContext` alone.
2019-08-16 16:13:33 -07:00
Niels BuwenandSebastian Rittau 5638d29203 Fix #3187 : Wrong Signatures in socketserver (#3189)
Fixes #3187
2019-08-16 17:08:23 +02:00
Jon DufresneandSebastian Rittau 0ee7c3c38b Update __import__ function annotations (#3188)
Per the docs, globals/locals is an optional argument.
Additionally, globals/locals can be any mapping type, not only a dict.
Likewise, fromlist can be any sequence (the docs mention a tuple, not a
list).
The function returns a ModuleType, not Any.
2019-08-16 11:03:00 +02:00
Rebecca ChenandJelle Zijlstra b873894e16 Fix a typo (self -> cls) in stdlib/2/subprocess.pyi. (#3185) 2019-08-14 18:14:30 -07:00
Ville SkyttäandJelle Zijlstra 1edd6cd8a8 Add Match.regs (#2819) 2019-08-10 20:21:54 -07:00
Benjamin PetersonandJelle Zijlstra baea5a7bc3 Widen the annotation of os.write to include buffer. (#3109) 2019-08-10 13:15:46 -07:00
Phil JonesandJelle Zijlstra 1dc24e1c67 Add nbytes to the memoryview definition (#3167)
`nbytes`, like `contiguous`, was added in Python 3.3.
2019-08-03 07:51:55 -07:00
Jon DufresneandSebastian Rittau f2fdb54765 Precise the type of Python 2 htmlentitydefs module (#3163)
The code and documentation specifies the values specifically as
dictionaries.
2019-07-31 15:45:50 +02:00
Jon DufresneandSebastian Rittau edee7cfb3c Remove unused import from stdlib/2/htmlentitydefs.pyi (#3162) 2019-07-31 09:06:02 +02:00
Ville SkyttäandSebastian Rittau c6cbe4da66 inspect: use more specific arg type for some source retrieve functions (#3155) 2019-07-30 17:53:56 +02:00
Ran BenitaandJelle Zijlstra c8e7d98c1f Allow function.__code__ in Python 2 (#3152)
The following code works:

    >>> print(sys.version)
    2.7.16 (default, Mar 11 2019, 18:59:25)
    >>> def f(): pass
    >>> print(f.__code__)
    <code object f at 0x7f8534ecc8a0, file "<stdin>", line 1>
    >>> isinstance(f.__code__, types.CodeType)
    True

but it didn't type-check with `mypy --python-version 2.7`.
2019-07-26 07:40:22 -07:00
Ville SkyttäandSebastian Rittau bf50612d76 inspect: get{doc,comments,module,sourcefile} can return None (#3137) 2019-07-24 22:05:01 +02:00
Ville SkyttäandSebastian Rittau 8e0d288ea4 json: require a JSONDecoder/JSONEncoder in cls (#3138) 2019-07-23 22:59:57 +02:00
NamanandJelle Zijlstra 9379cedfa7 remove itertools.accumulate from Python 2 stubs (#3135) 2019-07-19 22:31:32 -07:00