Fix native parser for quoted None types - #22091
Closed
daleselaji-dev wants to merge 1 commit into
Closed
daleselaji-dev wants to merge 1 commit into
daleselaji-dev wants to merge 1 commit into
Conversation
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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.
Fixes #22090
Problem
With the native parser enabled,
cast("None", value)is rejected withInvalid type comment or annotation, although the same quoted forward reference is accepted by the legacy parser and was accepted before theast-serialize0.12.0 upgrade.Root Cause
The native type-string parser represents the literal
Noneas aRawExpressionTypeinstead of theUnboundType("None")produced by the legacy parser. Semantic analysis therefore treats the cast target as an invalid string expression.Solution
Normalize the native parser's exact
Noneresult toUnboundType("None"), preserving the existing forward-reference behavior without changing other raw expression handling.Changes
Nonetype string.cast("None", value).Testing
check-newsemanal.test— 226 passed.check-newsemanal.test— 227 passed.mypy/test/test_nativeparse.py— 257 passed.cast("None", value).pre-commit run --files mypy/nativeparse.py test-data/unit/check-newsemanal.test— passed (Black, Ruff, codespell and repository hooks).python -m mypy --config-file mypy_self_check.ini -p mypy— 196 source files passed.git diff --check— passed.Compatibility/Risk
The change only affects the native parser's handling of the exact quoted
Nonetype expression. Other raw expression types and the legacy parser are unchanged.Notes for Reviewer
The regression is exposed by the
ast-serialize0.12.0 parser output. The fix keeps the compatibility behavior already provided by the legacy parser and is limited to the parser boundary.AI assistance was used during investigation and implementation; the final diff and test results are documented above.
Linked Issue
Fixes #22090