Repository navigation
fix(python): self.x() on an attribute no longer links another file's x - #3350
Merged
Merged
Conversation
colbymchenry
force-pushed
the
claude/issue-2958-self-attribute-call
branch
4 times, most recently
from
November 18, 2026 07:21
aeff2f7 to
fe96b4d
Compare
This was referenced Nov 18, 2026
The extractor records `self.x()` and `cls.x()` by the bare name, and when the class had no method `x`, nothing kept the call from name matching, which took any module-level function or variable `x` in the project, or another class's method `x`. flask's `ScriptInfo.load_app` calls `self.create_app()`, the callable it was handed, and linked an example app's `create_app`. resolveOneIn now asks pythonSelfCallReaches whether such a call can mean the target a strategy gave. It can when the target is a method of the class, of a project base, or of a subclass (an override the call runs on the subclass's instances), or a class. When the class or a base binds the attribute itself (`self.x = ...`, `cls.x = ...`, `x = ...` in its body), the call is that value, and the target only when the value names it under its own name: `self.x = x` for the module's `x`, `x = staticmethod(x)`, `self.Graph = nx.Graph`. A parameter of that name, an instance, or a tuple's element names nothing. With no binding, a module-level function or variable of another file is out of reach, a function of the caller's own file stays (a file can put its functions on its classes), and another class's method stays (a mixin calls into the class it is mixed into). Framework-resolved edges are left alone. Validation, against main (both arms with the 1.6.3 kernel, fresh init): - New test file, 10 cases: the 5 for the issue's shapes fail on main and pass now; 5 guards (own and inherited methods, a subclass override with a fallback binding, a mixin, what a binding names, a same-file function) pass on both. - flask: the issue's 2 edges are gone (cli.py:342 to the celery example's create_app, test_basic.py:299 to the conftest `app` fixture). - django's django/ package: 32 removed. 28 were wrong: a parameter, instance or class the attribute holds, linked to an unrelated class's method of the name (get_response 4, func 4, get_content_type 4, model 3, copy 3, log 2, read 2, and paginator, UserModel, path, get_lookups, iterator, exception_class once each). 4 were right at run time only: ddl_references' `self.quote_name()` (3), a parameter its callers fill with `connection.ops.quote_name`, and RelatedPopulator's `self.from_db()`, bound to a wrapper of the model's from_db. As with the shadowing locals of Issue 2732, nothing in the text tells those 4 from the 28. - httpx, click, express and gin: byte-identical. - Index CPU on django (median of 3, interleaved): 35.7 s -> 35.0 s, noise. - The 35 Python test files pass. PR #3217 by nilotpal-n7 targets this issue; this change is written from the issue and our own diagnosis, and also covers a method of an unrelated class reached through an attribute the class binds, which #3217 keeps. Fixes #2958 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
colbymchenry
force-pushed
the
claude/issue-2958-self-attribute-call
branch
from
November 18, 2026 08:10
fe96b4d to
8e8a7ed
Compare
This was referenced Nov 18, 2026
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.
Summary
In Python,
self.x()orcls.x()on an attribute that holds a callable no longer links to a same-named module-level function or variable in another file, and, when the class sets that attribute itself, no longer links to another class's method of that name. flask's app loading (ScriptInfo.load_appcallingself.create_app()) stops showing an example app as its callee.Root cause
The extractor records
self.x()andcls.x()by the bare name. When the class had no methodx, nothing kept the call from name matching, which took any module-level function or variablexin the project (the issue's cases), or another class's methodx(self.callback()afterself.callback = callbacklinkedOther.callback).Fix
pythonSelfCallReaches(name-matcher.ts), asked inresolveOneInfor every resolved Python call whose receiver isselforcls:self.x = …,cls.x = …, orx = …in its body), the call is that value: the target stays only when the value names it under its own name (self.x = xfor the module'sx,x = staticmethod(x),self.Graph = nx.Graph). A parameter of that name, an instance (self.out = Layer()) or a tuple's element (self.repo, self.run = …) names nothing;Validation
__tests__/python-self-attribute-call.test.ts, 10 cases: the 5 issue shapes (the flask repro, an instance attribute against a function and a variable, a tuple-bound attribute, another class's method, a class attribute oncls) fail on main and pass with the fix; 5 guards (own and inherited methods, a subclass override with a fallback binding, a mixin, what a binding names, a same-file function) pass on both.init:create_app, test_basic.py:299 → the conftestappfixturedjango/(3bdcd29)The 4 runtime-only edges: ddl_references'
self.quote_name()(3), a parameter its callers fill withconnection.ops.quote_name, and RelatedPopulator'sself.from_db(), bound to a wrapper of the model'sfrom_db. As with the shadowing locals kept out in #2732, nothing in the text tells these from the 28 wrong ones, so the change accepts them.CODEGRAPH_KERNEL_EXPECT=1, main's kernel, 4 workers): 929 files passed, 6 skipped; 11,501 tests passed, 2 expected failures, 93 skipped, 0 failed.Fixes #2958
PR #3217 by nilotpal-n7 targets this issue; this one is written from the issue and our own diagnosis, and also covers another class's method reached through an attribute the class binds, which #3217 keeps. Thanks to inth3shadows for the report.
🤖 Generated with Claude Code