Commit Graph
1190 Commits
Author SHA1 Message Date
Rebecca ChenandJelle Zijlstra fab2ee0d7c Remove unnecessary quotes around forward references. (#3191) 2019-08-16 20:29:32 -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
Ivan LevkivskyiandGitHub 3cfc3150f0 Partially restore old (imprecise) signature of Match.group() (#3190)
This partially reverts #3172
2019-08-16 19:53:52 +01:00
Niels BuwenandSebastian Rittau 5638d29203 Fix #3187 : Wrong Signatures in socketserver (#3189)
Fixes #3187
2019-08-16 17:08:23 +02:00
Ville SkyttäandJelle Zijlstra 1edd6cd8a8 Add Match.regs (#2819) 2019-08-10 20:21:54 -07:00
Sebastian RittauandJelle Zijlstra 628eee29f7 Use Literal in a few more places (#3176) 2019-08-10 13:08:18 -07:00
Sebastian RittauandGitHub 3f6cec9872 Fix Match.group problems (#3172)
* group() may return None values
* group() allows to mix int and str arguments
* Use concrete return type
* Merge overloads
2019-08-08 16:59:20 +02:00
Rebecca ChenandSebastian Rittau 6f01493edc Move some constants from tokenize to token in Python 3.7+. (#3175) 2019-08-08 08:45:08 +02:00
g.denisandSebastian Rittau 50f1988650 concurrent: add private classes and exceptions (#3169) 2019-08-07 10:39:15 +02:00
Cole MacleanandSebastian Rittau 29771aa1ee Add missing methods to asyncio stubs (#3088) 2019-08-06 08:34:38 +02:00
Jelle ZijlstraandGitHub d05a9d3d83 Improve enums (#3168)
I realized while working on srittau/type-stub-pep#64 that a
few things we do in existing enum definitions in typeshed are
problematic:

- Using "= ..." doesn't allow type checkers to correctly type the
  result of Enum.MEMBER.value. In fact, mypy at least infers
  .value to be "Ellipsis" if you do this.
- Properties on the enum values themselves, like HTTPStatus.phrase,
  should not be specified directly as attributes, because it makes
  type checkers think that the properties themselves are enum
  members.

I ended up doing a bit more cleanup to the signal module:
- Remove unnecessary ... initializers.
- Remove unnecessary _SIG = Signals alias.
- I don't have Windows to test, but the C code for _signal suggests
  that CTRL_C_EVENT and CTRL_BREAK events are not Signals, but just ints:
  https://github.com/python/cpython/blob/1dbd084f1f68d7293718b663df675cfbd0c65712/Modules/signalmodule.c#L1575
2019-08-05 08:08:57 -07:00
Nicklas LindgrenandJelle Zijlstra 3c4141982e Declare asyncio.as_completed() as taking an Iterable (#3164)
The stub for asyncio.as_completed declared it as taking a Sequence of
Futures. This was unnecessarily strict.

Just like asyncio.wait, asyncio.as_completed can be declared to take
an Iterable of Futures instead. Both these functions iterate over
their argument only once to store its items in a set, so an Iterable
is sufficiently strict. This has been true since the initial
implementation of the functions.
2019-07-31 10:53:23 -07:00
Jon DufresneandSebastian Rittau 02401c836f Add type annotations for Python 3 html.entities (#3161) 2019-07-31 15:46:16 +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
Sebastian RittauandGitHub 9ccf9356bf Remove Python 3.4 support (#3147)
Closes #3123
2019-07-27 10:58:21 +02:00
Kamil BarandSebastian Rittau 4697adcb1a [stdlib][3] Add missing typing.OrderedDict generic stub for Python 3.7.2 (#3153) 2019-07-26 20:46:15 +02:00
Vasily ZakharovandSebastian Rittau e9d1f86591 gettext stubs fixed (#3130) 2019-07-25 16:57:14 +02:00
Ville SkyttäandSebastian Rittau bf50612d76 inspect: get{doc,comments,module,sourcefile} can return None (#3137) 2019-07-24 22:05:01 +02:00
Sebastian RittauandJelle Zijlstra 0177dedc42 Add werkzeug.middleware (#3103)
HTTPConnection.timeout can be a float
2019-07-24 08:51:55 -07:00
Zsolt DollensteinandSebastian Rittau 8794e40d41 Fix ast.Constant availability (#3142) 2019-07-24 14:10:51 +02:00
Ville SkyttäandSebastian Rittau 8e0d288ea4 json: require a JSONDecoder/JSONEncoder in cls (#3138) 2019-07-23 22:59:57 +02:00
Daniel HahlerandSebastian Rittau 9dcdc7d481 faulthandler.dump_traceback_later: timeout can be float (#3134) 2019-07-21 01:04:25 +02:00
William AydandSebastian Rittau 8e89faa90f Added Optional (#3125)
Fixes #3124
2019-07-17 10:08:46 +02:00
Michael J. SullivanandGitHub 3ad3ed82c7 Overload the constructor of subprocess.Popen (#3113)
This takes advantage of a recent mypy change to respect the return
type of `__new__`. Using that it does the same tedious overloads
as `run` and `check_output`.
2019-07-16 15:41:33 -07:00
Ran BenitaandSebastian Rittau 4ae4714e00 sys: refine the return type of sys.exc_info() (#3111) 2019-07-11 10:43:37 +02:00
Michael J. SullivanandGitHub b43e1d674f Use Literal overloads to give better types to subprocess (#3110)
This gives better types to `subprocess.check_output` and `subprocess.run`
by laboriously overloading using literals.

To support `run`, I turned `CompletedProcess` into `_CompletedProcess[T]`
with `CompletedProcess = _CompletedProcess[Any]`. I could pretty easily
be convinced that it would be better to just make `CompletedProcess`
generic, though.

I'd like to do the same for Popen but need to make mypy support
believing the type of `__new__` in order for that to work.
2019-07-10 14:44:27 -07:00
Cole MacleanandJelle Zijlstra f5c107cacd BytesGenerator requires BinaryIO (#3106) 2019-07-07 22:03:07 -07:00
Sam ZhouandSebastian Rittau 4af283e1ac Fix HTTPConnection.putrequest parameter names (#3101) 2019-07-03 08:52:59 +02:00
ikelosandSebastian Rittau 3e700224ba Add in multiprocessing.managers.ValueProxy types (#3100)
Fixes #1778
2019-07-03 08:49:16 +02:00
Francis ColasandSebastian Rittau 75d9228b02 PurePath methods accept os.PathLike[str] from 3.6 (#3099)
Closes #3095
2019-07-02 13:08:32 +02:00
Maarten ter HuurneandJelle Zijlstra bdd49d0f3a Fix annotation of re.Match 'lastindex' and 'lastgroup' in Python 3 (#3085)
Both are None if there were no groups matched. Also 'lastgroup'
will be None if the matched group was nameless.

The Python 2 versions of these annotations already used Optional.
2019-06-22 10:18:16 -07:00
Jelle ZijlstraandSebastian Rittau b0c9fa4530 fix type of loop.sock_connect (#3073) 2019-06-21 17:31:51 +02:00
Jelle ZijlstraandGitHub 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
crusaderkyandSebastian Rittau 9941616b9e Add mp_context parameter to concurrent.futures.ProcessPoolExecutor (#3078)
Closes #3076
2019-06-20 19:42:26 +02:00
Rune TynanandJelle Zijlstra 58221cf20e Add types and functions in types.py that are new in 3.7 (#3066)
* Add types and functions in types.py that are new in 3.7

* Update `resolve_bases` to accept any iterable of objects, and the same
for `new_class` if the version is at least 3.7

* Add comparison overrides implemented by MethodWrapperType

* Fix mypy error due to over-constrained `__eq__`
2019-06-19 15:20:57 -07:00
Florian LudwigandJelle Zijlstra 2e10326b50 change http.cookies.Morsel to Dict[str, Any] (#3060)
Morsel does cast any value to string and therfor any is the correct
typehint. For some keys other types then strings are more
appropiate anyway, max-age can take an integer (unix time) and http-only
a boolean.

Closes #3059
2019-06-19 15:17:16 -07:00
Motoki NaruseandSebastian Rittau aa56af7dce HTMLParser.get_starttag_text() can return None (#3072) 2019-06-19 15:34:37 +02:00
Ivan LevkivskyiandGitHub 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
Carl MeyerandSebastian Rittau fcb97fe8f1 Overload ast.parse to recognize that mode=exec means Module return. (#3039) 2019-06-17 23:27:14 +02:00
Eric ArellanoandJelle Zijlstra d36a519b95 Update select and selectors to use _HasFileno protocol (#3057) 2019-06-15 16:35:18 -07:00
Utkarsh GuptaandSebastian Rittau 8e7c32846f request.pyi: Change Union[] -> Any for attributing status. (#3045)
Fixes #3026
2019-06-13 12:01:13 +02:00
John FreemanandSebastian Rittau e4a9cd580c Add missing path-like annotation (#3053)
Fixes #3052
2019-06-12 20:03:14 +02:00
Walter Scott JohnsonandSebastian Rittau 901cb33a3c Mark asyncio loop parameters as Optional (#3047) 2019-06-10 20:58:31 +02:00
Rebecca ChenandJelle Zijlstra e7184d6dfc Add undocumented but used method LWPCookieJar.as_lwp_str. (#3041)
The method is defined here:
https://github.com/python/cpython/blob/e36ed475ea429f7cc80a4d65f80b44686a74b246/Lib/http/cookiejar.py#L1864
2019-06-08 07:06:14 -07:00
nabnutandSebastian Rittau 87f96dc1f0 Add stub for queue.SimpleQueue in 3.7 (#2995)
Closes: #2994
2019-06-07 11:50:39 +02:00
J Rob GantandSebastian Rittau 40c4e4ff3d Annotate HTMLParser attribute optional value (#3034)
Closes #3031
2019-06-05 18:51:52 +02:00
Radu Matei LăcraruandSebastian Rittau a7785151aa Make AsyncGeneratorType.aclose() properly return Awaitable[None] (#3032) 2019-06-05 11:20:23 +02:00
Rebecca ChenandSebastian Rittau f8093d63cd Move stdlib/3/curses to stdlib/2and3/curses. (#3025)
Also add the A_ITALIC constant, which is new in 3.7.
2019-06-01 10:51:07 +02:00
Viktor RoytmanandSebastian Rittau 07d4938251 Add missing methods to ItemsView and KeysView, including isdisjoint (#2997) 2019-05-20 02:12:22 +02:00
Saul ShanabrookandSebastian Rittau 38a7f14658 Bound arguments are ordered (#2998)
The `arguments` attribute of the `BoundArguments` is specified as an "ordered, mutable mapping (collections.OrderedDict)"
not just a mutable mapping: https://docs.python.org/3/library/inspect.html#inspect.BoundArguments.arguments
2019-05-18 22:00:05 +02:00