Commit Graph
5845 Commits
Author SHA1 Message Date
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
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
Rune TynanandJelle Zijlstra 15b7cdaf40 Implement ZipExtFile in the zipfile type stubs (#3074) 2019-08-10 13:25:03 -07:00
Benjamin PetersonandJelle Zijlstra baea5a7bc3 Widen the annotation of os.write to include buffer. (#3109) 2019-08-10 13:15:46 -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
Evgeny DedovandSebastian Rittau 0dea39cb3c make basicConfig parameters Optional[...] (#3170) 2019-08-07 10:43:05 +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
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
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
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
Anthony SottileandSebastian Rittau 29dde6c883 Fix type annotations for get_wch / unget_wch (#3157) 2019-07-30 17:57:11 +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
BradandSebastian Rittau bd2d0fcc85 Add hints for 3 globals from logging/__init__.py (#3159) 2019-07-30 17:28:13 +02:00
Anthony SottileandSebastian Rittau 32a89809f0 curses: getch returns an integer (#3156) 2019-07-30 09:25:01 +02:00
Michael R. ShannonandSebastian Rittau 568f1ea555 Add attributes to xml.etree.ElementTree.ParseError. (#3158) 2019-07-30 08:48:28 +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
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
Connor BrintonandSebastian Rittau df8ecf5a67 Fix incorrectly named parameters in logging module (#3148) 2019-07-25 21:29:55 +02:00
Vasily ZakharovandSebastian Rittau e9d1f86591 gettext stubs fixed (#3130) 2019-07-25 16:57:14 +02:00
Maarten ter HuurneandSebastian Rittau 32ee49c79c Add zipfile.ZipFile.filename (#3104) 2019-07-25 11:26:39 +02:00
Ran BenitaandSebastian Rittau c9f9530224 xml.etree.ElementTree: use literal type for a more precise return value for tostring() (#3120) 2019-07-25 09:31:12 +02:00
Michael J. SullivanandSebastian Rittau b3f7be523a Fix __call__ type for GeneratorContextManager (#3143) 2019-07-24 22:20:15 +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
Ran BenitaandSebastian Rittau 9a7b286c66 warnings: ignore the type of category when message is a Warning (#3121) 2019-07-24 21:46:23 +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
NamanandJelle Zijlstra 9379cedfa7 remove itertools.accumulate from Python 2 stubs (#3135) 2019-07-19 22:31:32 -07:00
Michael J. SullivanandGitHub 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. SullivanandGitHub 90c2c22961 Make python 2 subprocess consistent with python 3 (#3132) 2019-07-19 10:56:59 -07:00
Sebastian RittauandJelle Zijlstra dad16f2d43 Update socket exceptions (#3127)
* error is an alias for OSError in Python 3
* herror and gaierror can be constructed without arguments (tested
  in Python 2.7 and 3.7)
* timeout uses the same arguments as herror and gaierror
2019-07-18 16:50:28 -07:00
YannackandSebastian Rittau 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
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
秋葉andSebastian Rittau e2ec5d0525 Make SyntaxError.text be optional (#3119)
Closes #3118
2019-07-15 09:11:45 +02:00
Anthony SottileandJelle Zijlstra f76b7b273b Re-export _curses._CursesWindow from curses (#3117) 2019-07-13 08:01:10 -07:00
Anthony SottileandJelle Zijlstra 2a57ce2cec Add curses.COLORS and curses.COLOR_PAIRS (#3115) 2019-07-13 07:50:13 -07:00
Brandt BucherandJelle Zijlstra 34b47101dd Slice attributes can be of any type. (#3024) 2019-07-11 12:13:32 -07:00