Skip to content

Move function-level stdlib imports to the top of the file - #936

Open
mircealungu wants to merge 1 commit into
masterfrom
wt/stdlib-imports
Open

mircealungu wants to merge 1 commit into
masterfrom
wt/stdlib-imports

Conversation

@mircealungu

Copy link
Copy Markdown
Member

Closes #935.

What changed

  • 59 function-level standard-library imports moved to the top of their files.
  • 62 function-level imports removed because the file already imports the same name at the top. Some of these are internal zeeguu.* imports. (The issue's 119 matched by module; matching by exact name gives 62.)
  • article.py now uses one form of datetime, so its two all_*_than functions no longer need a local import. They had no test, so I added one.
  • New check: zeeguu/core/test/test_stdlib_imports_at_top.py fails on a function-level stdlib import.

The edits were scripted with an AST pass, which skips any import whose name means something else at the top of the file.

Left alone

  • user.py: three local from datetime import ... imports stay. The top-level import datetime is the module, and about 20 uses depend on that. The check allows this kind of clash automatically, so there is no allowlist.
  • Third-party and other internal imports: out of scope, as in the issue.

Testing

  • Full suite, as CI runs it: passed.
  • The new check fails when a function-level import hashlib is put back.

🤖 Generated with Claude Code

Also drops function-level imports that repeat a top-level one, and adds a
test that keeps stdlib imports out of functions. article.py now uses one
form of datetime. user.py keeps its three local datetime imports: its
top-level `import datetime` means something else, and about 20 uses
depend on that.

Closes #935

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

ArchLens detected architectural changes in the following views:
diff
diff
diff

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.

Move function-level stdlib imports to the top of the file, and add a check

1 participant