fix: 型安全性の改善 - Pythonフックの型アノテーション強化とJS8進数リテラル修正 - #829
Conversation
## Python hooks - 型アノテーション改善
- common.py: parse_tool_context の戻り型を tuple → tuple[str, dict, dict] に精密化
- pre_git_quality_gates.py:
- detect_linter_conflicts: list → list[dict]
- get_package_scripts: dict → dict[str, str]
- run_with_retry: tuple → tuple[bool, dict]
- last_result の型アノテーション追加 (dict | None)
- post_git_push_ci.py:
- get_current_branch() → str | None の戻り型追加
- get_latest_run() → dict | None の戻り型追加
- watch_ci_run の run_id: int, timeout_seconds: int 型追加
- watch_ci_run の戻り型 → tuple[str, list]
- run_id が None の場合の早期リターン追加(実質バグ修正)
- post_pr_ci_watch.py: get_pr_checks → tuple[str, list] の戻り型追加
- post_pr_ai_review.py: post_pr_comment → bool の戻り型追加
## JavaScript - 型安全な書き方に改善
- test/config-validation.test.js: parseInt('111', 8) → 0o111 (明示的な8進数リテラル)
- test/config-validation.test.js: parseInt('004', 8) → 0o004
Closes #828
Co-authored-by: keito4 <keito4@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughType annotations are added or tightened on public functions across five Python Claude hook scripts ( ChangesType Safety Improvements (Issue
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Claude finished @keito4's task in 3m 50s —— View job コードレビュー
総評変更は全体的に質が高く、型安全性の向上とバグ修正を適切に実現しています。承認推奨 です。 ファイル別レビュー
|
| 箇所 | 指摘 |
|---|---|
post_pr_ci_watch.py:39 / post_git_push_ci.py:105 |
tuple[str, list] のリストが未特殊化。list[dict] にするとより正確 |
common.py |
Optional / Union と str | None スタイルの混在(今回スコープ外) |
結論
- バグ修正(
run_id is Noneチェック)は価値ある修正 - 型アノテーションは実装と正確に対応している
- JS の 8 進数リテラル化はコード品質向上
- critical / major の問題なし → APPROVE
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cbe3804740
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
|
|
||
| def get_current_branch(): | ||
| def get_current_branch() -> str | None: |
There was a problem hiding this comment.
Keep post-push hook annotations Python 3.9-compatible
In macOS/local setups where these hooks are invoked with the system python3 (the hook wiring calls plain python3 in .claude/settings.json), this PEP 604 annotation is evaluated when the function is defined and Python 3.9 raises TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'. That makes the post-push CI hook crash after a successful git push instead of reporting CI status; use Optional[str]/Optional[dict] or add from __future__ import annotations before using | here.
Useful? React with 👍 / 👎.
|
(aside) |
|
Claude finished @keito4's task in 9m 33s —— View job CI修正完了 ✅
修正内容原因: PEP 604の 修正ファイル:
コミット: |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.claude/hooks/common.py:
- Around line 25-29: The project uses Python 3.10+ syntax throughout the hook
files (union types like str | None and lowercase generics like tuple[str, dict],
list[dict], dict[str, str]) but has no declared minimum Python version in its
configuration. This will silently break for users on Python 3.9 or earlier. Add
or update a project configuration file to explicitly require Python 3.10 or
later by adding requires-python = ">=3.10" to pyproject.toml (recommended), or
python_requires=">=3.10" to setup.py, or create .python-version with 3.10 or
later. The affected hook files at .claude/hooks/common.py (lines 25-29),
.claude/hooks/post_git_push_ci.py (lines 61-72, 75-102, 105-140),
.claude/hooks/post_pr_ai_review.py (lines 186-203),
.claude/hooks/post_pr_ci_watch.py (lines 41-100), and
.claude/hooks/pre_git_quality_gates.py (lines 74-115, 118-128, 156-220) do not
require direct code changes as they correctly use 3.10+ syntax; the
configuration-level fix will resolve the compatibility issue across all these
files.
In @.claude/hooks/post_git_push_ci.py:
- Line 61: The code uses Python 3.10+ union type syntax (str | None, dict |
None, tuple[str, list]) in multiple function signatures including
get_current_branch at line 61, but the repository lacks any Python version
constraint configuration. Create a new `.python-version` file in the repository
root and specify Python 3.10 as the minimum required version to ensure runtime
compatibility across all locations where this modern syntax is used.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 658bca23-6e0c-4c2b-a7aa-8d53e0524c1f
📒 Files selected for processing (6)
.claude/hooks/common.py.claude/hooks/post_git_push_ci.py.claude/hooks/post_pr_ai_review.py.claude/hooks/post_pr_ci_watch.py.claude/hooks/pre_git_quality_gates.pytest/config-validation.test.js
| def parse_tool_context(data: dict) -> tuple[str, dict, dict]: | ||
| """Extract standard tool context fields. | ||
|
|
||
| Returns: | ||
| tuple: (tool_name, tool_input, tool_response) | ||
| tuple[str, dict, dict]: (tool_name, tool_input, tool_response) |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
What is the minimum Python version for the repository?
💡 Result:
The minimum Python version requirement for a repository is not universal and varies depending on the specific project. To determine the minimum Python version for a given repository, you should check the project's configuration files: 1. Look for a pyproject.toml file in the root directory and inspect the requires-python field [1][2][3][4]. 2. Check the setup.py file for a python_requires argument or a variable defining supported versions (e.g., SUPPORTED_PYTHON_VERSIONS) [5][6]. 3. Consult the README.md or CONTRIBUTING.md files, which often document environment requirements [1]. Many modern Python projects have standardized on Python 3.10 as a minimum version [7][1][2][3][4]. If you are looking for the requirement for a specific repository, please provide the name or URL of the repository so that the exact version can be verified.
Citations:
- 1: google/adk-python@8402832
- 2: https://github.com/kserve/kserve/blob/master/python/kserve/pyproject.toml
- 3: https://github.com/scikit-learn/scikit-learn/blob/38a68483bddccd238c75e99977d614d72f47f7d7/pyproject.toml
- 4: https://github.com/openai/openai-agents-python/blob/3a11cf52/pyproject.toml
- 5: https://github.com/snowflakedb/snowpark-python/blob/1d1b64890b54b761aa10d360d898d4273a0ad476/setup.py
- 6: https://github.com/huggingface/transformers/blob/master/setup.py
- 7: Update minimum python version to 3.10 syssi/esphome-smg-ii#100
🏁 Script executed:
#!/bin/bash
# Check for pyproject.toml
if [ -f "pyproject.toml" ]; then
echo "=== pyproject.toml ==="
cat pyproject.toml | head -50
fi
# Check for setup.py
if [ -f "setup.py" ]; then
echo "=== setup.py ==="
head -50 setup.py
fi
# Check for .python-version
if [ -f ".python-version" ]; then
echo "=== .python-version ==="
cat .python-version
fi
# Check for setup.cfg
if [ -f "setup.cfg" ]; then
echo "=== setup.cfg ==="
head -30 setup.cfg
fi
# Look for any Python version specifications in CI files
if [ -d ".github/workflows" ]; then
echo "=== GitHub Actions workflows ==="
find .github/workflows -type f -name "*.yml" -o -name "*.yaml" | head -5 | xargs -I {} sh -c 'echo "File: {}"; cat "{}" | grep -i "python" -A 2 -B 2 | head -20'
fiRepository: keito4/config
Length of output: 488
🏁 Script executed:
#!/bin/bash
# Read pyproject.toml if it exists and look for python requirement
echo "=== Checking pyproject.toml ==="
if [ -f "pyproject.toml" ]; then
cat pyproject.toml | head -100
else
echo "pyproject.toml not found"
fi
echo ""
echo "=== Checking .python-version ==="
if [ -f ".python-version" ]; then
cat .python-version
else
echo ".python-version not found"
fi
echo ""
echo "=== Checking CI workflow for Python version ==="
if [ -f ".github/workflows/ci.yml" ]; then
cat .github/workflows/ci.yml
fiRepository: keito4/config
Length of output: 11647
🏁 Script executed:
#!/bin/bash
# Check if the hook files exist
echo "=== Checking for Python hook files ==="
ls -la .claude/hooks/*.py 2>/dev/null || echo "Hook files not found"
echo ""
echo "=== Checking for pre-commit configuration ==="
if [ -f ".pre-commit-config.yaml" ]; then
cat .pre-commit-config.yaml
else
echo ".pre-commit-config.yaml not found"
fi
echo ""
echo "=== Checking README for Python version info ==="
if [ -f "README.md" ]; then
grep -i "python" README.md | head -20
else
echo "README.md not found"
fi
echo ""
echo "=== Listing all config files ==="
find . -maxdepth 2 -type f \( -name "*.toml" -o -name "*.cfg" -o -name "*.ini" -o -name ".python*" \) 2>/dev/nullRepository: keito4/config
Length of output: 1438
🏁 Script executed:
#!/bin/bash
echo "=== Checking ruff.toml for Python version ==="
if [ -f "ruff.toml" ]; then
cat ruff.toml
else
echo "ruff.toml not found"
fi
echo ""
echo "=== Checking .codex/config.toml ==="
if [ -f ".codex/config.toml" ]; then
cat .codex/config.toml
else
echo ".codex/config.toml not found"
fi
echo ""
echo "=== Checking .gitleaks.toml ==="
if [ -f ".gitleaks.toml" ]; then
head -50 .gitleaks.toml
fi
echo ""
echo "=== Checking for any Python version reference in codebase ==="
rg "requires-python|python_requires|3\.9|3\.10|3\.11" --type toml --type py . 2>/dev/null | head -20Repository: keito4/config
Length of output: 3727
🏁 Script executed:
#!/bin/bash
# Check the actual hook files for Python version requirements
echo "=== Checking common.py for union syntax ==="
head -35 .claude/hooks/common.py
echo ""
echo "=== Checking post_git_push_ci.py for union syntax ==="
head -80 .claude/hooks/post_git_push_ci.py | tail -25
echo ""
echo "=== Checking for shebang lines in hook files ==="
head -1 .claude/hooks/common.py
head -1 .claude/hooks/post_git_push_ci.py
head -1 .claude/hooks/pre_git_quality_gates.py
echo ""
echo "=== Searching for any Python version specification in hook files ==="
rg "python" .claude/hooks/ | grep -i "version\|3\.[0-9]" || echo "No version specs found in hooks"Repository: keito4/config
Length of output: 1890
🏁 Script executed:
#!/bin/bash
echo "=== common.py type annotations ==="
grep -n "def\|->.*:" .claude/hooks/common.py | head -20
echo ""
echo "=== post_git_push_ci.py type annotations ==="
grep -n "def.*->.*:" .claude/hooks/post_git_push_ci.py | head -15
echo ""
echo "=== post_pr_ai_review.py type annotations ==="
grep -n "def.*->.*:" .claude/hooks/post_pr_ai_review.py | head -15
echo ""
echo "=== post_pr_ci_watch.py type annotations ==="
grep -n "def.*->.*:" .claude/hooks/post_pr_ci_watch.py | head -15
echo ""
echo "=== pre_git_quality_gates.py type annotations ==="
grep -n "def.*->.*:" .claude/hooks/pre_git_quality_gates.py | head -15Repository: keito4/config
Length of output: 1574
🏁 Script executed:
#!/bin/bash
echo "=== Checking common.py for union syntax usage ==="
rg "\|" .claude/hooks/common.py | head -10
echo ""
echo "=== Checking post_git_push_ci.py for union syntax usage ==="
rg "\|" .claude/hooks/post_git_push_ci.py | head -10
echo ""
echo "=== Checking pre_git_quality_gates.py for union syntax usage ==="
rg "\|" .claude/hooks/pre_git_quality_gates.py | head -10
echo ""
echo "=== Checking all hook files for lowercase generic syntax ==="
rg "list\[|dict\[|tuple\[" .claude/hooks/*.py | head -20
echo ""
echo "=== Summary: Python version requirements needed ==="
echo "Files using 3.10+ syntax:"
echo "- common.py: tuple[str, dict, dict] at line 25"
echo "- post_git_push_ci.py: str | None (lines 61, 75), tuple[str, list] (line 105)"
echo "- post_pr_ci_watch.py: tuple[str, list] (line 41)"
echo "- pre_git_quality_gates.py: list[dict] (line 74), dict[str, str] (line 118)"Repository: keito4/config
Length of output: 1658
Add Python 3.10+ minimum version requirement to project configuration.
The hook files use Python 3.10+ syntax (union types X | None and lowercase generic types like list[dict], dict[str, str], tuple[str, list]) but the project has no declared Python version requirement. This will silently break for users on Python 3.9 or earlier. Create or update a configuration file with an explicit minimum:
- Add
requires-python = ">=3.10"topyproject.toml(recommended) - OR add
python_requires=">=3.10"tosetup.py - OR create
.python-versionwith3.10or later
Affected files using 3.10+ syntax:
.claude/hooks/common.py:tuple[str, dict, dict].claude/hooks/post_git_push_ci.py:str | None,dict | None,tuple[str, list].claude/hooks/post_pr_ci_watch.py:tuple[str, list].claude/hooks/pre_git_quality_gates.py:list[dict],dict[str, str],dict | None,tuple[bool, dict].claude/hooks/post_edit_auto_lint.py:list[str]
📍 Affects 5 files
.claude/hooks/common.py#L25-L29(this comment).claude/hooks/post_git_push_ci.py#L61-L72.claude/hooks/post_git_push_ci.py#L75-L102.claude/hooks/post_git_push_ci.py#L105-L140.claude/hooks/post_pr_ai_review.py#L186-L203.claude/hooks/post_pr_ci_watch.py#L41-L100.claude/hooks/pre_git_quality_gates.py#L74-L115.claude/hooks/pre_git_quality_gates.py#L118-L128.claude/hooks/pre_git_quality_gates.py#L156-L220
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.claude/hooks/common.py around lines 25 - 29, The project uses Python 3.10+
syntax throughout the hook files (union types like str | None and lowercase
generics like tuple[str, dict], list[dict], dict[str, str]) but has no declared
minimum Python version in its configuration. This will silently break for users
on Python 3.9 or earlier. Add or update a project configuration file to
explicitly require Python 3.10 or later by adding requires-python = ">=3.10" to
pyproject.toml (recommended), or python_requires=">=3.10" to setup.py, or create
.python-version with 3.10 or later. The affected hook files at
.claude/hooks/common.py (lines 25-29), .claude/hooks/post_git_push_ci.py (lines
61-72, 75-102, 105-140), .claude/hooks/post_pr_ai_review.py (lines 186-203),
.claude/hooks/post_pr_ci_watch.py (lines 41-100), and
.claude/hooks/pre_git_quality_gates.py (lines 74-115, 118-128, 156-220) do not
require direct code changes as they correctly use 3.10+ syntax; the
configuration-level fix will resolve the compatibility issue across all these
files.
PEP 604のユニオン型構文(X | None)はPython 3.10+のみサポート。 Python 3.9環境でフックが実行時エラーになる問題を修正。 typing.OptionalはPython 3.5+で利用可能。 Fixes: Codexレビュー指摘 (post_git_push_ci.py:61) Co-authored-by: keito4 <keito4@users.noreply.github.com>
|
🎉 This PR is included in version 1.116.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Closes #828
変更内容
Python hooks - 型アノテーション強化
JavaScript
Generated with Claude Code
Summary by CodeRabbit
Release Notes
Bug Fixes
Refactor
Tests
parseInt(..., 8)for readability.