Adds some version ranges for submodules that are available in different
versions that their parent modules.
I noticed these while updating pytype's pinned typeshed commit. pytype
can't actually use this submodule version information yet, but from what
I understand, all type checkers at least handle this information
gracefully (by ignoring it), so it doesn't hurt to add it.
* collections.abc is available in Python 3.3 and later. _collections_abc
is imported by the collections.abc stub, so its version range is also
changed from 3.6- to 3.3-.
* _typeshed.tkinter needs to be 3.0-, since it imports tkinter, which is
marked as 3.0-.
* importlib.metadata is available in 3.8 and later.
* Extract _socket.pyi from socket.pyi.
* Extract _socket.socket from socket.socket.
* Fix socket.family annotation.
* Annotate SocketIO properly.
* SocketType is an alias of _socket.socket.
* Sort items in socket.pyi in the same order as in socket.py.
* Remove socket.EINTR.
* Use _typeshed.WriteableBuffer instead of custom alias.
* Add errorTab (Windows only).
* Add _socket.dup().
* Mark positional-only argments.
* Remove constructors from socket exceptions.
* socket.timeout is an alias for TimeoutError, starting with Python 3.10.
* Use PEP 604 in changed lines.
* Add alias for fileno arguments.
* getaddrinfo() port can be bytes.
* Explicitly override some SSLSocket methods.
* Allow ReadableBuffer in _CMSG arguments.
As brought up in https://github.com/python/typeshed/pull/5516
Alternatives include:
- Use another type var that has a value restriction
- Doing something fancy with Protocols that have a __bool__ that returns
a Literal (which may not work)
- Doing nothing
* Move socket from AbstractServer to Server.
* Fix Server.socket type on Python 3.7+.
* Use Iterable instead of list for socket argument.
Closes: #5535
* mock: fix overloads
Fixes#5533. This changes the order and in some cases removes default
values from new.
* ignore incompatible overlaps
Co-authored-by: hauntsaninja <>
Add operators or and ror for types.Union and ror to the type class.
Also, add modified isinstance and issubclass signatures to support old-style and new-style unions inside.
Noticed this in mypy-primer output in #5516 on this code: https://github.com/encode/starlette/blob/master/starlette/testclient.py#L74
It calls `iscoroutinefunction()` on an object that may be None, which got flagged as an error but is actually fine; it just returns False.
We could also potentially use TypeGuard here, especially for `iscoroutine` which is just an `isinstance` call.