Fixes#4288.
- Default imports to THIRD_PARTY, so in effect we merge the FIRST_PARTY and THIRD_PARTY stubs. This means import order is no longer affected by whether typing_extensions is installed locally.
- Treat typing_extensions, _typeshed and some others as standard library modules.
Note that isort master is very different from the latest release; we'll have to do something
different if and when the next isort release comes out.
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.
Started out as progress towards #1476, but I ended up fixing a few more things:
- fixed the signature of _encode_type, which actually returns a pair, not a string
- made some attributes into properties in order to prevent the descriptor protocol from turning them into methods
- found a bug in CPython in the process (python/cpython#6779)
I used the following test file to make sure these classes are now instantiable:
```python
import codecs
import io
from typing import IO
bio = io.BytesIO()
cod = codecs.lookup('utf-8')
codecs.StreamReaderWriter(bio, codecs.StreamReader, codecs.StreamWriter)
codecs.StreamRecoder(bio, cod.encode, cod.decode, codecs.StreamReader, codecs.StreamWriter)
```