refactor: move all imports to module top-level#10
Merged
Conversation
All package and sub-module imports now appear at the top of each file rather than inside functions, following Python best practices. - src/__init__.py: move importlib.metadata import to top - src/regex_scanner.py: move datetime and time to top - src/ai_scanner.py: move RegexScanner import to top (no circular dep) - src/utils.py: move click, requests to top; consolidate inquirer into a single top-level try/except with _HAS_INQUIRER flag - src/providers/bedrock.py: move boto3 to top-level try/except with _HAS_BOTO3 guard for clear ImportError on missing optional dep - tests/test_regex_scanner.py: move tempfile, os to top Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
src/__init__.py—importlib.metadatamoved to top (Python ≥3.9 always has it)src/regex_scanner.py—datetimeandtime(stdlib) moved to topsrc/ai_scanner.py—RegexScannermoved to top (confirmed no circular dep)src/utils.py—clickandrequests(required deps) moved to top; all threefrom inquirer import ...calls inside functions collapsed into a single top-leveltry/except ImportErrorwith a_HAS_INQUIRERflagsrc/providers/bedrock.py—boto3(optional dep) moved to top-leveltry/exceptwith a_HAS_BOTO3guard; raises a clearImportErrormessage when missingtests/test_regex_scanner.py—tempfileandosmoved to topWhy
Imports inside functions are a Python anti-pattern:
Optional deps (
boto3,inquirer) are handled via top-leveltry/except ImportError— the standard Python idiom.Test plan
uv run --with pytest pytest tests/ -v→ 150 passed🤖 Generated with Claude Code