fix(stubgen): emit from typing import Literal when Literal annotations are added#4144
Open
tobyh-canva wants to merge 1 commit into
Open
fix(stubgen): emit from typing import Literal when Literal annotations are added#4144tobyh-canva wants to merge 1 commit into
from typing import Literal when Literal annotations are added#4144tobyh-canva wants to merge 1 commit into
Conversation
tobyh-canva
commented
Jul 14, 2026
Comment on lines
-61
to
-67
| pub uses_self: bool, | ||
| /// Whether any item renders a `Callable[...]` annotation (so we know | ||
| /// whether to emit `from typing import Callable`). | ||
| pub uses_callable: bool, | ||
| /// Whether any item renders a `ClassVar[...]` annotation (so we know | ||
| /// whether to emit `from typing import ClassVar`). | ||
| pub uses_classvar: bool, |
Contributor
Author
There was a problem hiding this comment.
Since this PR would have required me adding another bool uses_literal, I figured I might as well take this opportunity to consolidate all these bools into a set typing_imports.
But please do let me know if the bools are preferred
0d0fd44 to
e18129a
Compare
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Contributor
|
@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D111931494. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Currently, stubgen emits inferred
Literalannotations, but forgets to addfrom typing import Literalat the top of the file.Additionally, as shown by the existing
class_varssnapshot test, enum members are currently incorrectly annotated withLiteral, whereas the typing spec says enum members should not be annotated at all (ref).Changes
typingimports in stubgen