Skip to content

fix(brain-repo): secrets_scanner silently fails to import on Python 3.9#125

Open
mt-alarcon wants to merge 1 commit into
evolution-foundation:developfrom
mt-alarcon:fix/secrets-scanner-py39-future-annotations
Open

fix(brain-repo): secrets_scanner silently fails to import on Python 3.9#125
mt-alarcon wants to merge 1 commit into
evolution-foundation:developfrom
mt-alarcon:fix/secrets-scanner-py39-future-annotations

Conversation

@mt-alarcon

@mt-alarcon mt-alarcon commented Jul 22, 2026

Copy link
Copy Markdown

Summary

secrets_scanner.py uses PEP 604 union syntax (list[str] | None) in
function signatures. Without from __future__ import annotations,
this syntax raises TypeError at import time on Python 3.9 —
still a common interpreter (e.g. /usr/bin/python3 ships 3.9.x on
macOS).

The dangerous part: any caller that wraps the import/scan call in a
broad try/except and falls back to an empty result set on failure
loses 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 annotations at the top of the
module, so annotations are evaluated lazily as strings. No behavior
change on 3.10+, restores compatibility with 3.9.

Test plan

  • /usr/bin/python3 --versionPython 3.9.6
  • Before fix: import brain_repo.secrets_scanner under 3.9.6 raises
    TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
  • After fix: same import succeeds under 3.9.6
  • Existing module test suite (111 tests) still passes under the
    project's normal Python 3.11 environment

🤖 Generated with Claude Code

Summary by Sourcery

Bug Fixes:

  • Prevent import-time TypeError in secrets_scanner on Python 3.9 due to use of PEP 604 union syntax without postponed evaluation of annotations.

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)
@sourcery-ai

sourcery-ai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures 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

Change Details Files
Make type annotations lazily evaluated to restore Python 3.9 compatibility and prevent import-time TypeError in the secrets scanner module.
  • Add future import to enable postponed evaluation of type annotations that use PEP 604 union syntax
  • Rely on the unchanged runtime behavior for Python 3.10+ while fixing import behavior on Python 3.9
dashboard/backend/brain_repo/secrets_scanner.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant