Skip to content

fix(python): keep a one-line def or class suite scope across semicolons - #842

Merged
rowkav09 merged 1 commit into
mainfrom
fix-inline
Oct 4, 2026
Merged

rowkav09 merged 1 commit into
mainfrom
fix-inline

Conversation

@rowkav09

@rowkav09 rowkav09 commented Oct 4, 2026

Copy link
Copy Markdown
Member

def f(): pass; import importlib as il followed by a module-level
il.import_module("requests") credited requests: the semicolon continuation
sits at the same indent as the header, so the scope was closed and the local
import landed in module scope. Statements on the physical line where a def or
class header ends now stay in that scope. The next physical line ends it as
before.

Fixes #841.

`def f(): pass; import importlib as il` followed by a module-level
`il.import_module("requests")` credited requests: the semicolon continuation
sits at the same indent as the header, so the scope was closed and the local
import landed in module scope. Statements on the physical line where a def or
class header ends now stay in that scope. The next physical line ends it as
before.
@rowkav09
rowkav09 merged commit 5c8d401 into main Oct 4, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: importlib alias in a one-line def/class suite with a semicolon leaks to module scope

1 participant