Repository navigation
Take the TYPE_CHECKING branch over its else when inferring names - #963
Open
marlon-costa-dc wants to merge 2 commits into
Open
marlon-costa-dc wants to merge 2 commits into
marlon-costa-dc wants to merge 2 commits into
Conversation
Static analysis assumes `typing.TYPE_CHECKING` is true (PEP 484), but rope
took the last assignment, so in
if TYPE_CHECKING:
Alias = Checked
else:
Alias = Runtime
`Alias` inferred as `Runtime`, and classes based on it lost their base.
The scope visitor records, on each assignment, the tests of the `if`
statements whose `else` holds it. Inference skips assignments under the
`else` of a test that reads `typing.TYPE_CHECKING`, followed through
imports, attributes of imported modules and a name's single plain
assignment, without inferring any object. The constant is recognized as the
`TYPE_CHECKING` attribute of the module named `typing`, whatever its value.
Other tests, `not TYPE_CHECKING` and rebound names keep today's behaviour.
Decisions are kept in the module's concluded data.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #963 +/- ##
=======================================
Coverage 95.44% 95.45%
=======================================
Files 134 134
Lines 26910 26995 +85
=======================================
+ Hits 25685 25768 +83
- Misses 1225 1227 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
The upstream test workflows wait for maintainer approval on fork PRs. For reference, this head passed the fork's full CI test matrix: https://github.com/marlon-costa-dc/rope/actions/runs/44976350714 |
This branch has not been deployed
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.
Static analysis assumes
typing.TYPE_CHECKINGis true (PEP 484), but rope takes the last assignment of a name, so inAliasinfers asRuntime, andDerivedgets the runtime base instead of the declared one.This makes inference skip assignments that sit in the
elseof anifwhose test readstyping.TYPE_CHECKING:ifstatements whoseelseholds it (AssignmentValue.orelse_tests).TYPE_CHECKING = typing.TYPE_CHECKINGintyping_extensions), without inferring any object. The constant is recognized as theTYPE_CHECKINGattribute of the module namedtyping, whatever its value, so a projecttypingmodule bindingTYPE_CHECKING = Falsestill reads as true.not TYPE_CHECKING, and a rebound name keep today's behaviour. Decisions are kept in the module's concluded data.Tests cover
TYPE_CHECKING,typing.TYPE_CHECKING,t.TYPE_CHECKINGand a once-bound alias (the if/else pick fails on master), class bases read through the alias, the undecided cases, and a project-localtypingmodule.Local run (CPython 3.13):
pytest2182 passed, 7 skipped, 5 xfailed, 7 subtests passed; the one error,test_get_package_tuple_compiled, comes from that interpreter's statically linked_sqlite3and is unrelated. pre-commit (black, isort, whitespace) passes.🤖 Generated with Claude Code