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.
Make the Python 2 and 3 concurrent.futures stubs identical so fixes get
applied to both.
For example, #1305 and #2233 fixed the same problem at different times,
as did #1078 and #1911.
By making the stubs identical, we apply the fix from #1711 to Python 2.
Fixes#2234.
The generic type of the futures provided to the wait method cannot
currently be preserved through this definition. For now deleting the
unused NamedTuple is the best approach.
Specifically, this solves a problem in code such as:
with ThreadPoolExecutor() as p: ...
Where the p variable would be typed as an abstract `Executor`, rather than the specific `ThreadPoolExecutor` as expected.
* Allow None in concurrent.futures.exception() and set_exception()
* Make Executor.map() signature more precise
* Remove superfluous signatures
* Specify str type for some concurrent.futures constants
* Update concurrent.futures backport
* CR fixes
The concurrent.futures.Future class's set_exception() method might be
called with a BaseException that is not an Exception, so change
set_exception()'s parameter type from Exception to BaseException. The
exception set via set_exception() is returned by exception(), so
change exception()'s return type from Exception to BaseException.
* Fixed types in stdlib/3/concurrent/futures:
- Remove private classes from public interface
- Add missing types
* Remove "generated by stubgen" headers from modified type stubs
* - Use ... as default value
- Fix space formatting
* Replace more default values with '...'
* Use 'None' as default value where specified by documentation
* Use explicit Optional[T] type instead of default value None