Skip to content

fix: make check_copyright_year run on Python 3.9 - #1002

Open
ivany-nv wants to merge 1 commit into
mainfrom
ivany-nv/fix-copyright-hook-py39
Open

fix: make check_copyright_year run on Python 3.9#1002
ivany-nv wants to merge 1 commit into
mainfrom
ivany-nv/fix-copyright-hook-py39

Conversation

@ivany-nv

@ivany-nv ivany-nv commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

scripts/check_copyright_year.py:21 annotates -> int | None. PEP 604 unions in annotations are evaluated at import time before Python 3.10, so on 3.9 the hook raises before it checks anything:

TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

Fix: one line — from __future__ import annotations, matching what check_lfs_pointers.py:6 already does.

Why this went unnoticed since February. Two things compound: .github/workflows/pre-commit.yaml:23 sets SKIP: check-copyright-year, so CI never runs it; and anyone on Python 3.10+ sees it pass. Only a 3.9 contributor hits it — and it fails open for them: it never reports a stale year because it never starts.

Tested on 3.9.6 and 3.12.13, plain and --fix, plus pre-commit run over the changed file. Before: 3.9 raises, 3.12 passes. After: both pass.

One thing to know before merging. With the hook alive again, pre-commit run --all-files wants to update the year on ~101 files that drifted while it was dead — headers that stopped at 2025 while git says the file was touched in 2026. That backlog is deliberately not in this PR: it is a bulk, legal-adjacent edit that deserves its own review. It also self-heals, since the next commit touching any of those files fixes it.

Summary by CodeRabbit

  • Style
    • Improved import formatting in the copyright-year checking script.
    • No user-visible behavior changes.

Line 21 annotates `-> int | None`. PEP 604 unions in an annotation are
evaluated at import time before 3.10, so on 3.9 the module raises TypeError
before it checks anything:

    def git_last_modified_year(path: Path) -> int | None:
    TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

`from __future__ import annotations` defers annotation evaluation, which is
what the other local hook scripts already do (check_lfs_pointers.py:6).

This has been silent since the script landed, for two compounding reasons:
the workflow sets SKIP: check-copyright-year, so CI never runs it, and anyone
whose python3 is 3.10 or newer sees it pass. Only a 3.9 contributor hits it,
and the hook fails open from their point of view -- it never reports a stale
year because it never starts.

Tested: python3.9.6 and python3.12.13, plain and --fix, plus `pre-commit run`
over the changed file. Before the change 3.9 raises and 3.12 passes; after it,
both pass.

Note for whoever merges: with the hook running again, `--all-files` now wants
to update the year on ~101 files that drifted while it was dead. That backlog
is deliberately not in this commit -- it is a separate, reviewable change.

Signed-off-by: Ivan Yang <yifanyang@nvidia.com>
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d8a7b2f4-3289-425d-9372-f7d72cf0f184

📥 Commits

Reviewing files that changed from the base of the PR and between ade37f9 and 99ba6f6.

📒 Files selected for processing (1)
  • scripts/check_copyright_year.py

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


📝 Walkthrough

Walkthrough

The change adds from __future__ import annotations to scripts/check_copyright_year.py and inserts a separating blank line before the remaining imports. No runtime behavior or public declarations change.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 99ba6

This localized change restores the copyright check on Python 3.9 without altering its intended behavior; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: making check_copyright_year run on Python 3.9.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ivany-nv/fix-copyright-hook-py39

Comment @coderabbitai help to get the list of available commands.

@ivany-nv
ivany-nv requested a review from jiwenc-nv August 24, 2026 17:28
@ivany-nv
ivany-nv enabled auto-merge (squash) August 24, 2026 21:51
@jiwenc-nv

Copy link
Copy Markdown
Collaborator

Isn't Python 3.9 EOL already? Just curious what triggered the complaint on Python 3.9?

@ivany-nv

Copy link
Copy Markdown
Contributor Author

hook runs PATH's python3 at commit time — 3.9.6 on macOS,
whatever venv the project uses — and it fails at import, so it silently looks like it passed.
@jiwenc-nv

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.

2 participants