Clarify why some module-level objects in typing have default values (#7037)

This commit is contained in:
Alex Waygood
2022-01-29 01:38:25 +00:00
committed by GitHub
parent 470ea31ccd
commit 7e79706ddd
4 changed files with 24 additions and 14 deletions

View File

@@ -41,16 +41,23 @@ _T = TypeVar("_T")
def overload(func: _F) -> _F: ...
# Unlike the vast majority module-level objects in stub files,
# these `_SpecialForm` objects in typing need the default value `= ...`,
# due to the fact that they are used elswhere in the same file.
# Otherwise, flake8 erroneously flags them as undefined.
# `_SpecialForm` objects in typing.py that are not used elswhere in the same file
# do not need the default value assignment.
Union: _SpecialForm = ...
Optional: _SpecialForm
Tuple: _SpecialForm
Generic: _SpecialForm = ...
# Protocol is only present in 3.8 and later, but mypy needs it unconditionally
Protocol: _SpecialForm = ...
Callable: _SpecialForm = ...
Type: _SpecialForm = ...
ClassVar: _SpecialForm
NoReturn: _SpecialForm = ...
Optional: _SpecialForm
Tuple: _SpecialForm
ClassVar: _SpecialForm
if sys.version_info >= (3, 8):
Final: _SpecialForm
def final(f: _T) -> _T: ...