fix(brain-repo): secrets_scanner silently fails to import on Python 3.9#125
Open
mt-alarcon wants to merge 1 commit into
Open
Conversation
secrets_scanner.py uses PEP 604 union syntax (list[str] | None) in function signatures without `from __future__ import annotations`. On Python 3.9 (e.g. /usr/bin/python3 on macOS), the module-level import raises TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'. Callers that swallow the import exception (e.g. an integrity-check script that catches broad exceptions and falls back to an empty result set) silently lose secret-scanning coverage instead of failing loudly — the exact failure mode this scanner exists to prevent. Any EvoNexus install with a Python 3.9 interpreter on PATH hits this. Fix: add `from __future__ import annotations` so the annotations are evaluated lazily as strings (no runtime effect on py3.10+, restores py3.9 compatibility). Verified: - `/usr/bin/python3` (3.9.6) import now succeeds (previously raised TypeError at import time) - Full existing test suite for this module still passes (111 passed)
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsures the secrets scanner module imports correctly on Python 3.9 by making type annotations lazily evaluated, preventing silent failures in secret scanning due to PEP 604 union syntax incompatibility. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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
secrets_scanner.pyuses PEP 604 union syntax (list[str] | None) infunction signatures. Without
from __future__ import annotations,this syntax raises
TypeErrorat import time on Python 3.9 —still a common interpreter (e.g.
/usr/bin/python3ships 3.9.x onmacOS).
The dangerous part: any caller that wraps the import/scan call in a
broad
try/exceptand falls back to an empty result set on failureloses secret-scanning coverage silently — no error surfaced to the
user, no log noise, just an empty findings list. That's the exact
failure mode a secret scanner exists to prevent, and it's entirely
dependent on which Python interpreter happens to be on
PATH.Fix
One line: add
from __future__ import annotationsat the top of themodule, so annotations are evaluated lazily as strings. No behavior
change on 3.10+, restores compatibility with 3.9.
Test plan
/usr/bin/python3 --version→Python 3.9.6import brain_repo.secrets_scannerunder 3.9.6 raisesTypeError: unsupported operand type(s) for |: 'type' and 'NoneType'project's normal Python 3.11 environment
🤖 Generated with Claude Code
Summary by Sourcery
Bug Fixes: