Commit Graph

507 Commits

Author SHA1 Message Date
Bouteillebleu
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 Benita
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 Benita
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 Benita
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 Lee
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 Buwen
5638d29203 Fix #3187 : Wrong Signatures in socketserver (#3189)
Fixes #3187
2019-08-16 17:08:23 +02:00
Jon Dufresne
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 Chen
b873894e16 Fix a typo (self -> cls) in stdlib/2/subprocess.pyi. (#3185) 2019-08-14 18:14:30 -07:00
Ville Skyttä
1edd6cd8a8 Add Match.regs (#2819) 2019-08-10 20:21:54 -07:00
Benjamin Peterson
baea5a7bc3 Widen the annotation of os.write to include buffer. (#3109) 2019-08-10 13:15:46 -07:00
Phil Jones
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 Dufresne
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 Dufresne
edee7cfb3c Remove unused import from stdlib/2/htmlentitydefs.pyi (#3162) 2019-07-31 09:06:02 +02:00
Ville Skyttä
c6cbe4da66 inspect: use more specific arg type for some source retrieve functions (#3155) 2019-07-30 17:53:56 +02:00
Ran Benita
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ä
bf50612d76 inspect: get{doc,comments,module,sourcefile} can return None (#3137) 2019-07-24 22:05:01 +02:00
Ville Skyttä
8e0d288ea4 json: require a JSONDecoder/JSONEncoder in cls (#3138) 2019-07-23 22:59:57 +02:00
Naman
9379cedfa7 remove itertools.accumulate from Python 2 stubs (#3135) 2019-07-19 22:31:32 -07:00
Michael J. Sullivan
4072ad82fb Fix python 2 subprocess.Popen to produce Popen[bytes] (#3133)
Otherwise this causes a lot of spurious errors.
2019-07-19 14:17:32 -07:00
Michael J. Sullivan
90c2c22961 Make python 2 subprocess consistent with python 3 (#3132) 2019-07-19 10:56:59 -07:00
Yannack
40215d1fa3 Fix the definition of nsmallest() in stdlib/2 and 2and3/heapq.pyi (#3114)
Missing support of the optional "key" kwarg in nsmallest.
Also fixed nlargest syntax for 2and3 which was also missing.
Use a protocol for heapq.py
2019-07-18 21:38:28 +02:00
秋葉
e2ec5d0525 Make SyntaxError.text be optional (#3119)
Closes #3118
2019-07-15 09:11:45 +02:00
Brandt Bucher
34b47101dd Slice attributes can be of any type. (#3024) 2019-07-11 12:13:32 -07:00
Ran Benita
4ae4714e00 sys: refine the return type of sys.exc_info() (#3111) 2019-07-11 10:43:37 +02:00
Jason Gilholme
8b66e08745 Add Generic Typing to Queue.PriorityQueue and Queue.LifoQueue in python 2 (#3036) 2019-07-01 14:05:13 +02:00
Chad Dombrova
e25c0cb128 "key" argument of builtin function sorted should be optional in python 2.7 (#3086) 2019-06-22 14:09:51 -07:00
Jelle Zijlstra
ada0570efc Revert "Define functools.partial as overloaded function instead of its own class (#2878)" (#3077)
This reverts commit e45f443d85.
2019-06-20 20:39:49 -07:00
Ivan Levkivskyi
01c2fa5a14 Sync recent typing and typing_extensions updates (#3070)
This includes two things to sync up with recent runtime updates:
* Move `Final`, `@final`, `Literal`, and `TypedDict` to `typing` (`typing_extensions` still defines or re-exports them)
* Rename `@typing.runtime` to `@typing.runtime_checkable`, while keeping `@runtime` as a backwards-compatible alias in `typing_extensions`.
2019-06-18 02:31:54 +01:00
Jadiker
5447ff6bfe str and unicode format functions take objects (#3068) 2019-06-17 20:09:11 +02:00
Rebecca Chen
d64a26cf99 Add missing constructor to types.CodeType. (#3040)
I got the argument order from
2bfc2dc214/Objects/codeobject.c (L263)
and the types from the attributes already in the stub.
2019-06-08 07:07:29 -07:00
Rebecca Chen
e7184d6dfc Add undocumented but used method LWPCookieJar.as_lwp_str. (#3041)
The method is defined here:
e36ed475ea/Lib/http/cookiejar.py (L1864)
2019-06-08 07:06:14 -07:00
Paul Dagnelie
d13eb937f7 Implement SupportsIndex (#2996) 2019-05-16 21:55:57 -07:00
Chad Dombrova
840631657f Add undocumented member glob.has_magic (#2972) 2019-05-16 11:28:49 +02:00
Mark Mendoza
2cf4af784c Convert typing.ContextManager.exit to use dunder parameter names (#2980) 2019-05-15 13:30:20 -07:00
Ivan Levkivskyi
50d98acc76 Remove redundant variable definitions in ast module (#2986) 2019-05-13 19:32:24 +02:00
Ivan Levkivskyi
75723e3885 Add an optional opener parameter to open() function (#2977)
Fixes #2976
2019-05-09 16:59:32 +02:00
Chad Dombrova
feb74cf9de Add subprocess.list2cmdline for python 2 (#2971) 2019-05-08 10:21:32 +02:00
Jelle Zijlstra
b5493e8639 add types.FunctionType.__init__ (#2968)
Fixes #2930
2019-05-07 17:31:01 +02:00
Jelle Zijlstra
bdb1de57f5 narrow signature of __contains__ for str-like classes (#2967)
Fixes #2937
2019-05-07 10:24:28 -04:00
berdario
e45f443d85 Define functools.partial as overloaded function instead of its own class (#2878) 2019-05-06 12:05:02 -04:00
Jan Szopinski
bf2d51742b unittest: Add overloads to assert(Not)AlmostEqual(s) (#2901) 2019-05-05 15:15:17 -04:00
Jia Chen
c4b249c9a8 Use dunder parameter name in _Writer.write (#2954) 2019-05-04 22:51:39 -04:00
Brandt Bucher
1fddec3f90 Positional-only arguments for built-in functions. (#2921) 2019-04-30 11:22:25 +02:00
Benjamin Peterson
4e572ae6a3 Remove format_map from Python 2 unicode. (#2933) 2019-04-24 00:42:27 +01:00
Rebecca Chen
fd57aee5da Make shlex.shlex convertable to a list in Python 2. (#2927)
This simply copies the relevant lines over from the Python 3 stub.
2019-04-21 09:21:00 +02:00
Michael Lee
efb67946f8 Use variable annotations everywhere (#2909) 2019-04-13 10:40:52 +02:00
Michael J. Sullivan
f06f2e97bb Make os.altsep Optional on non-win32 platforms (#2918)
Keep it str on win32 to avoid breaking win32-specific code that relies
on it.
2019-04-12 23:00:19 -07:00
Sebastian Rittau
bd10d8aad4 Add @typing.type_check_only (#2679)
Cf. python/typing#597
2019-04-12 15:32:22 -07:00
Brandt Bucher
4230e6f313 Fix quit's argument and return types to match those of exit. (#2915)
Fixes #2912.
2019-04-12 16:57:26 +02:00
Michael J. Sullivan
0350e9fa89 Fix some issues with __round__ (#2907)
In python 3, add an overload for there being no digits argument
and make it return int.

In python 2, __round__ doesn't exist and SupportsRound doesn't exist
in the typing module. Use SupportsFloat for python 2 round().

Remove decimal's __round__ overload that takes None, since it doesn't exist
2019-04-09 11:45:10 -07:00