The _types module can house any common type defintions used throughout
the rest of typeshed to keep defintions in sync.
First candidate is file descriptors where anything with `fileno()`
method is accepted. There were several different implementations in
various files that can be unified.
`HTTPConnection` only passes timeout down to `socket.settimeout()` which is of type `Optional[float]` and has a specific action for `None`. `HTTPConnection` should support the same behavior
The documentation states:
* datagram_received: "data is a bytes object containing the incoming data."
* pipe_data_received: "data is a non-empty bytes object containing the received data."
While these implementations don't matter for the 'typing' module
itself, these are also imported to serve as the implementations
for the 'collection.abc' module.
Fixes#3029
Fixes#3547
This removes some type safety in exceptional cases, like code that interacts
directly with cached_property objects, but that seems like a price worth
paying.
* Run black code formatter on tempfile.pyi
* Use Literal to improve SpooledTemporaryFile
Previously, SpooledTemporaryFile was always an AnyStr.
Now, we load a SpooledTemporaryFile[bytes] if we open in bytes mode,
and we load a SpooledTemporaryFile[str] if we open in str mode.
Nothing in the standard library documentation for the string module suggests that the value associated with any key in the mapping parameter(or kwds) to Template.substitute and Template.safe_substitute should be a string. In fact any object can be used, for example
Template("$number is a number.").substitute({"number": 1})
The above code sample currently causes an error message like this:
error: Dict entry 0 has incompatible type "str": "int"; expected "str": "str"
which obviously shouldn't be emitted. Also a similar logic is already in place for methods in the Formatter class. However as I saw the notice about loose types above the Formatter class, I opted to use `object` instead of `Any` as the implementation inside the affected functions just uses the built-in str function on values inside mappings.