Commit Graph

14 Commits

Author SHA1 Message Date
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
Sebastian Rittau
9ccf9356bf Remove Python 3.4 support (#3147)
Closes #3123
2019-07-27 10:58:21 +02:00
Michael Lee
efb67946f8 Use variable annotations everywhere (#2909) 2019-04-13 10:40:52 +02:00
Rebecca Chen
9b9ff64fc5 tempfile.mkdtemp() should return a str when passed no arguments. (#2893)
Otherwise, pytype expands `AnyStr` to `Union[str, bytes]`, leading
to spurious type errors later on.

* Mark the `dir` argument to mkdtemp as AnyStr.
2019-03-29 23:11:42 +01:00
Ruud van Asseldonk
b7d6bab83f Fix stub for SpooledTemporaryFile (#2452)
Fixes #2431
2018-11-20 11:03:21 +01:00
Sebastian Rittau
006a79220f Flake8 fixes (#2549)
* Fix over-indented continuation lines

* Fix under-indented continuation lines

* Fix whitespace around default operator problems

* Limit line lengths

* Fix inconsistent files
2018-10-24 07:20:53 -07:00
Russell Cloran
a62c6be905 Make encoding and newline optional in tempfile (#1995)
`encoding` and `newline` have a default value of `None` in stdlib, for all of
the classes/functions that take these parameters.
2018-03-28 16:41:24 -07:00
Jelle Zijlstra
26d1ff8352 add tempfile.TMP_MAX for py3 (#1353) 2017-05-25 19:33:05 -07:00
Jelle Zijlstra
155fdd0cd4 Fixes to tempfile stubs (#981)
Fixes #975

And a few more things I noticed while reading the tempfile docs.

    In 3.5, most functions in tempfile were changed to accept either str or bytes in their prefix and suffix arguments, and return bytes or str accordingly. This seemed like a case for AnyStr.
    We were missing tempdirb and tempprefixb, added in 3.5.
    TemporaryFile and others were declared as returning BinaryIO, but they actually return either binary or text IO depending on the mode passed in. I changed the return type to IO[Any], similar to builtins.open.
2017-03-12 19:32:46 -07:00
Lukasz Langa
6b5c6626d6 Fixing flake8 E121, E122, E123, E124, E125, E126 errors 2016-12-19 23:53:19 -08:00
Danny Weinberg
708fd960da Fix errors in stubs when running in strict mode (#515) 2016-09-02 19:04:56 -07:00
Matthias Kramm
94c9ce8fd0 Consistently use '= ...' for optional parameters. 2015-11-09 13:55:02 -08:00
Matthias Kramm
d2a3d4a4ed Use explicit "# type: str" instead of '' shortcut. 2015-11-09 07:59:24 -08:00
Matthias Kramm
337abed05a add (overwrite with) mypy stubs, if available 2015-09-30 09:59:44 -07:00