Skip to content

fix(audit): catch tokenize.TokenError, not the nonexistent TokenizeError#56

Closed
misnaej wants to merge 1 commit into
devfrom
fix/tokenize-tokenerror
Closed

fix(audit): catch tokenize.TokenError, not the nonexistent TokenizeError#56
misnaej wants to merge 1 commit into
devfrom
fix/tokenize-tokenerror

Conversation

@misnaej

@misnaej misnaej commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Summary

tokenize has no TokenizeError — the real exception is tokenize.TokenError. Three audit modules used the wrong name in except clauses, so a tokenization failure raised AttributeError (the except clause itself blows up) instead of being caught and logged.

Changes

  • audit/claims.py:321, audit/suppressions.py:286, audit/dup.py:180TokenizeErrorTokenError
  • tests/audit/test_dup.py — regression test: unterminated source (x = (1 +) now returns [] instead of raising
  • Bump plugin.json → 1.23.3 (patch)

How it was found

pyrefly (run at strict, while dogfooding the new opt-in typecheck step from #55) flagged [missing-attribute] No attribute TokenizeError in module tokenize. ruff doesn't check stdlib attribute existence and no test hit the failure path, so it sat latent.

Testing

Full suite green; new regression test added.

Breaking Changes

None.

- tokenize has no TokenizeError — the three except clauses (claims, suppressions, dup) raised AttributeError on a tokenization failure instead of catching it
- Surfaced by pyrefly; add a regression test feeding unterminated source
- Bump plugin.json to 1.23.3
@misnaej

misnaej commented Jun 17, 2026

Copy link
Copy Markdown
Owner Author

Folded into #55 (commit cfe3b31) per the one-PR decision. The tokenize.TokenError fix + regression test now ride along with the precommit-step-framework PR. Closing to avoid splitting the work across two PRs.

@misnaej misnaej closed this Jun 17, 2026
@misnaej misnaej deleted the fix/tokenize-tokenerror branch June 17, 2026 12:52
misnaej added a commit that referenced this pull request Jun 17, 2026
- StepDef registry with --only/--skip/enable/disable overrides (closes #6)
- Three opt-in steps: doctest, pyrefly typecheck, doc-consistency CLI (closes #5, #48, #4)
- Config-path validation; CONFIG_KEYS drift tests (closes #46)
- Fix tokenize.TokenError in audit modules; regression test (closes #56)
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