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
Rebecca Chen
b873894e16 Fix a typo (self -> cls) in stdlib/2/subprocess.pyi. (#3185) 2019-08-14 18:14:30 -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
Chad Dombrova
feb74cf9de Add subprocess.list2cmdline for python 2 (#2971) 2019-05-08 10:21:32 +02:00
Michael Lee
efb67946f8 Use variable annotations everywhere (#2909) 2019-04-13 10:40:52 +02:00
Yusuke Miyazaki
6192cce9d9 Avoid using string literals in type annotations (#2294) 2018-07-02 20:23:29 -07:00
Cooper Lees
4656153478 Allow subprocess stdout + stderr be Optional (#1375)
- Adding optional to _FILE for stderr + stdout arguments to subprocess functions
- Sometimes you might want subprocess commands to be quiet and other time print the output
2017-06-01 17:46:14 -07:00
Jelle Zijlstra
1d6e3f492e Fix incorrect usage of AnyStr (#1215)
* Fix incorrect usage of AnyStr

- sqlite3 was using Union[bytes, AnyStr], which doesn't make sense
- The urllib functions I changed accept either bytes or str for their "safe"
  argument
- Also added supports for PathLike to pstats
- Remove some unused imports of AnyStr

* pstats: python 2 accepts unicode
2017-04-27 08:47:59 -07:00
Guido van Rossum
fd77dd2e7a Make type of 'env' more flexible (#1091)
See https://github.com/python/typeshed/pull/1059#issuecomment-289150121
2017-03-24 15:58:01 -07:00
Josiah Boning
62f57e4cef Improve types for subprocess module (#1059)
* Improve types for CalledProcessError

This adds union types in the constructor to account for parameters that
might be either byte strings or unicode strings. At the same time, this
*removes* specific types from the user-accessible fields, to avoid the
need for users to at every use site specify which types their particular
instance was instantiated with.

* remove 'moral' comments; add List import; change 'str' to 'Text'

* import Text

* List -> Sequence; reinsert 'moral' comments

* Regularize string types everywhere

This defines _TXT and _CMD aliases, and uses them everywhere applicable.

Also brings the _FILE alias to python3.

* fix typo; possibly fix indentation

* remove trailing comma, which caused problems in python 2 tests

* fix py2 outputs to be bytes; tweak descriptive comments; remove one AnyStr
2017-03-24 08:23:36 -07:00
Lukasz Langa
fe0e3744cc Fixing flake8 E261 errors 2016-12-19 22:09:35 -08:00
George King
dccc29bc2f Add None to type union for subprocess.Popen.communicate input. (#743)
* Add `None` to type union for `subprocess.Popen.communicate` stub's `input` parameter.

* subprocess.communicate `input` annotated as `Optional[AnyStr]` for both 2.7 and 3.x; `timeout` as `Optional[float]`.
2016-12-07 14:46:34 -08:00
Guido van Rossum
cb97bb54c0 Move 2.7 to 2 (#635)
Closes #579.
2016-10-26 16:24:49 -07:00