Skip to content

Conversation

@brianschubert
Copy link
Member

Per PEP 563, typing.TYPE_CHECKING is intended to be a constant. It seems sensible to annotate it as such.

(Apparently some projects do modify it (e.g. sphinx autodoc temporarily sets it to True to help with import analysis), but that sort of use case seems dubious/exceptional enough to warrant a # type: ignore.)

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2024

Diff from mypy_primer, showing the effect of this PR on open source code:

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/ext/autodoc/importer.py: note: In function "import_object":
+ sphinx/ext/autodoc/importer.py:182:25: error: Cannot assign to final name "TYPE_CHECKING"  [misc]
+ sphinx/ext/autodoc/importer.py:188:25: error: Cannot assign to final name "TYPE_CHECKING"  [misc]

@TeamSpen210
Copy link
Contributor

It should probably be a literal too?

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should make this a literal. This will be special cased by type checkers anyway, but it's unclear whether it should be True or False in the stubs, i.e. whether the stubs should represent runtime or type checking time.

@srittau srittau merged commit 318cebb into python:main Dec 3, 2024
63 checks passed
kbaikov pushed a commit to kbaikov/typeshed that referenced this pull request Dec 5, 2024
@cdce8p cdce8p mentioned this pull request Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants