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

@@ -23,12 +23,19 @@ _promote = object()
class _SpecialForm(object):
def __getitem__(self, typeargs: Any) -> object: ...
Union: _SpecialForm = ...
Optional: _SpecialForm
Tuple: _SpecialForm
# 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.
Generic: _SpecialForm = ...
Protocol: _SpecialForm = ...
Callable: _SpecialForm = ...
Union: _SpecialForm = ...
Optional: _SpecialForm
Tuple: _SpecialForm
Type: _SpecialForm
ClassVar: _SpecialForm
Final: _SpecialForm