At this point, it is too late to add methods to these semi-protocols as
it would break lots of existing code. Additionally, we are moving away
from these classes to finer-grained protocols anyway.
write() is inherited from IO[bytes], where it's defined as
`def write(self, s: AnyStr) -> int: ...`. If AnyStr is bytes,
this should accept bytes, bytearray, and memoryview, so the
overload is unnecessary.
Closes: #4201
The return type of `__eq___` should be `bool`.
Otherwise, `mypy --disallow-any-unimported --no-silence-site-packages`
fails because the return type becomes `Union[bool, Any]` due to an
unfollowed import.
* typing: fix argument names of cast
* typing: use private _Alias class
For py37 and above, this is _GenericAlias, for py36 and below it's
_TypeAlias. I don't think we need to make typing.pyi definitions
correspond more precisely, but we should avoid leaking a
typing.TypeAlias class
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
* Add os.add_dll_directory()
* Add memfd_create() and flags
* Add type annotation to flags
* Add stat_result.st_reparse_tag and flags
* Add ncurses_version
* Add Path.link_to()
* Add Picker.reducer_override()
* Add plistlib.UID
* Add has_dualstack_ipv6() and create_server()
* Add shlex.join()
* Add SSL methods and fields
* Add Python 3.8 statistics functions and classes
* Remove obsolete sys.subversion
* Add sys.unraisablehook
* Add threading.excepthook
* Add get_native_id() and Thread.native_id
* Add Python 3.8 tkinter methods
* Add CLOCK_UPTIME_RAW
* Add SupportsIndex
* Add typing.get_origin() and get_args()
* Add unicodedata.is_normalized
* Add unittest.mock.AsyncMock
Currently this is just an alias for Any like Mock and MagicMock. All of
these classes should probably be sub-classing Any and add their own
methods. See also #3224.
* Add unittest cleanup methods
* Add IsolatedAsyncioTestCase
* Add ElementTree.canonicalize() and C14NWriterTarget
* cProfile.Profile can be used as a context manager
* Add asyncio task name handling
* mmap.flush() now always returns None
* Add posonlyargcount to CodeType
This was discussed in #3181 and the correct explanation was given that
object ought to be preferred here. In practice this caused an obscure
issue with mypy when using this operations on the results of
six.viewkeys(), since it decided that it wanted a mapping *from* object
as a result of inference contexts. Grumble.
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.
Both are None if there were no groups matched. Also 'lastgroup'
will be None if the matched group was nameless.
The Python 2 versions of these annotations already used Optional.
This includes two things to sync up with recent runtime updates:
* Move `Final`, `@final`, `Literal`, and `TypedDict` to `typing` (`typing_extensions` still defines or re-exports them)
* Rename `@typing.runtime` to `@typing.runtime_checkable`, while keeping `@runtime` as a backwards-compatible alias in `typing_extensions`.
According to Ivan, PEP 544 intentionally did not specify whether method conformance check in protocol inference should look at parameter names. For example, it's up to the type checker to decide whether a class with method defined as `def foo(self, x: int)` would implement a protocol with method `def foo(self, y: int)`.
Mypy decided to ignore parameter names altogether, but we Pyre team decided to be more strict and refuse to match different parameter names (as it is unsound to do so when those methods are invoked with named parameters). Since we rely on the typeshed stubs, we want to make sure at least the important stubs on typeshed conform to our standard.
This PR changes `Container.__contains__` to use dunder (i.e. positional-only) parameter name specified in PEP484. This change should not affect mypy since it ignores parameter names, but will make Pyre happy as it eliminate the naming requirement for all classes that want to conform to the `Container` protocol.
In python 3, add an overload for there being no digits argument
and make it return int.
In python 2, __round__ doesn't exist and SupportsRound doesn't exist
in the typing module. Use SupportsFloat for python 2 round().
Remove decimal's __round__ overload that takes None, since it doesn't exist