Repository navigation
fix: resolve module-level names bound through another instance - #156
Merged
Merged
Conversation
A module-level name denotes what its value denotes in a function body: an alias, an attribute, an item or a call of an import or of an earlier module-level name, resolved in statement order.
This was referenced Sep 25, 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
A module-level name now denotes what its value denotes in a function body, so the calls made through it resolve. Previously only a call of an imported symbol bound a name (
app = Flask(__name__)). A name bound through another module-level name stayed unknown, and so did every call made through it.Closes #155.
cursor = conn.cursor()afterconn = sqlite3.connect(...)python.sqlite3.connect.cursorsame = connpython.sqlite3.connectrun = os.systempython.os.systemhome = os.environ['HOME']python.os.environ: an item carries its container's symbol, asderive_symbolsdoesraw = connections['default'].cursor()python.django.db.connections.cursorNames resolve in statement order. A binding that uses a name before the module binds it stays unresolved.
Scope
analyze_symbols, through a private_denoted.SymbolTable.resolve_expressionis unchanged: it also resolves annotations, decorators and class bases, where an item such aslist[str]must not becomelist.db = client.shop). They now resolve, aspython.pymongo.MongoClient.shop.users.find_one. Modelling the dynamic database and collection names is a separate change.Tests
test_module_level_names_bound_through_an_instance_denote_what_a_function_derives: alias, attribute, item, call chain, statement order, a constant.test_a_query_through_a_module_level_cursor_is_an_injection: end to end, a Flask route executing a query through a module-level sqlite3 cursor is asql-injection.Both failed before the fix. Locally: 1124 passed; regression snapshots 19 passed, unchanged;
ruff checkandmypyclean.