In Python 3:
- The `mmap` type is `Iterable[int]`, not `Iterable[bytes]`.
- The `read_byte` method returns an `int`, and the `write_byte` method only accepts an `int` as its first and only argument.
- The `__setitem__` method accepts any `ReadableBuffer` object, not just `bytes`.
In both Python 2 and 3:
- The `__delitem__` method always raises a `TypeError`, so the proper return type is `NoReturn`.
- The `mmap` type isn't generic, so I've simplified the stubs by removing the unnecessary `_mmap` class.
* Use PEP 604, instead of Optional.
* Override FileHandler.stream and setStream to require a TextIOWrapper
instead of a SupportsWrite object.
* FileHandler._open() now returns a TextIOWrapper instead of IO. Using
anything but a file opened in text mode would not work.
The documentation for [`signal.signal`][1] points out that the current
annotation for signal handlers might be wrong (emphasis my own):
> The handler is called with two arguments: the signal **number** and the
> current stack frame (**`None` or** a frame object; for a description of frame
> objects, see the description in the type hierarchy or see the attribute
> descriptions in the `inspect` module).
And when we use them, we can see that the signal number is passed as an `int`,
not a `signal.Signals` member:
import signal
def handler(signal_number, frame):
print("In signal handler!")
print("Signal number:", signal_number, type(signal_number))
print("Stack frame: ", frame, type(frame))
# Set signal handler:
signal.signal(signal.SIGHUP, handler)
# Use it:
signal.raise_signal(signal.SIGHUP)
Which prints:
In signal handler!
Signal number: 1 <class 'int'>
Stack frame: <frame at 0x7f804402abe0, file '<stdin>', line 12, code <module>> <class 'frame'>
[1]: https://docs.python.org/3/library/signal.html#signal.signal
* pyright: disable reportUnknownParameterType
Unknown parameter types are preferred over Any annotations for
incomplete stubs. Especially larger stubs are expected to be
incomplete for some time and it would be a shame to lose the
other pyright warnings for those stubs.
* Also disable reportUnknownVariableType
Fix problems with tkinter
* Disable reportUnknownMemberType
Fix pyright problems
* Rework Match.group handling
Standardize group(), groups(), groupdict(), and __getattr__() to return
Any instead of AnyStr. Also special case group(0) and __getattr__(0) to
always return AnyStr. Use PEP 604 for unions in changed lines.
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.