Skip to content

[Python] More typing fixes #21

[Python] More typing fixes

[Python] More typing fixes #21

name: Python Type Checking
on:
pull_request:
branches: [main]
paths:
- 'src/Fable.Transforms/Python/**'
- 'src/fable-library-py/**'
- 'tests/Python/**'
- 'pyrightconfig.ci.json'
- 'pyproject.toml'
permissions:
contents: read
pull-requests: write
jobs:
pyright:
runs-on: ubuntu-latest
env:
UV_LINK_MODE: copy
steps:
- uses: actions/checkout@v5
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"
- name: Setup dotnet tools
run: dotnet tool restore
- name: Set up Python 3.12
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install uv
run: |
pipx install uv
pipx install maturin
- name: Build Python (compile only)
run: ./build.sh test python --compile-only
- name: Run Pyright and collect errors
id: pyright
continue-on-error: true
run: |
# Get excluded files from CI config
EXCLUDED_FILES=$(grep '"temp/' pyrightconfig.ci.json | sed 's/.*"\(temp[^"]*\)".*/\1/' | sort)
# Run pyright on all files (without CI excludes) and capture output
PYRIGHT_OUTPUT=$(uv run pyright temp/tests/Python/ temp/fable-library-py/ 2>&1 || true)
# Parse errors per file
ERROR_COUNTS=$(echo "$PYRIGHT_OUTPUT" | grep " - error:" | sed 's/:.*//g' | sed 's|.*/Fable/||' | sort | uniq -c | sort -rn)
# Calculate total errors
TOTAL_ERRORS=$(echo "$ERROR_COUNTS" | awk '{sum += $1} END {print sum+0}')
# Count files with errors
FILE_COUNT=$(echo "$ERROR_COUNTS" | grep -c '[0-9]' || echo "0")
# Check for new files with errors (not in exclude list)
NEW_FILES=""
HAS_NEW_ERRORS=false
while IFS= read -r line; do
if [ -n "$line" ]; then
FILE=$(echo "$line" | awk '{print $2}')
COUNT=$(echo "$line" | awk '{print $1}')
if ! echo "$EXCLUDED_FILES" | grep -q "^${FILE}$"; then
NEW_FILES="${NEW_FILES}| \`${FILE}\` | ${COUNT} | :warning: **NEW** |\n"
HAS_NEW_ERRORS=true
fi
fi
done <<< "$ERROR_COUNTS"
# Build error table for excluded files
EXCLUDED_TABLE=""
while IFS= read -r line; do
if [ -n "$line" ]; then
FILE=$(echo "$line" | awk '{print $2}')
COUNT=$(echo "$line" | awk '{print $1}')
if echo "$EXCLUDED_FILES" | grep -q "^${FILE}$"; then
EXCLUDED_TABLE="${EXCLUDED_TABLE}| \`${FILE}\` | ${COUNT} | Excluded |\n"
fi
fi
done <<< "$ERROR_COUNTS"
# Set outputs
echo "total_errors=$TOTAL_ERRORS" >> $GITHUB_OUTPUT
echo "file_count=$FILE_COUNT" >> $GITHUB_OUTPUT
echo "has_new_errors=$HAS_NEW_ERRORS" >> $GITHUB_OUTPUT
echo "new_files<<EOF" >> $GITHUB_OUTPUT
echo -e "$NEW_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "excluded_table<<EOF" >> $GITHUB_OUTPUT
echo -e "$EXCLUDED_TABLE" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Run pyright with CI config to check if excluded files pass
if uv run pyright --project pyrightconfig.ci.json temp/tests/Python/ temp/fable-library-py/; then
echo "ci_passed=true" >> $GITHUB_OUTPUT
else
echo "ci_passed=false" >> $GITHUB_OUTPUT
fi
- name: Get excluded files count
id: excluded
run: |
COUNT=$(grep -c '"temp/' pyrightconfig.ci.json || echo "0")
echo "count=$COUNT" >> $GITHUB_OUTPUT
- name: Find existing comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Python Type Checking
- name: Create or update PR comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
## Python Type Checking Results (Pyright)
| Metric | Value |
|--------|-------|
| Total errors | ${{ steps.pyright.outputs.total_errors }} |
| Files with errors | ${{ steps.pyright.outputs.file_count }} |
| Excluded files | ${{ steps.excluded.outputs.count }} |
| New errors | ${{ steps.pyright.outputs.has_new_errors == 'true' && ':x: Yes' || ':white_check_mark: No' }} |
${{ steps.pyright.outputs.has_new_errors == 'true' && '### :warning: New Files with Errors
These files are NOT in the exclude list and must be fixed or added to `pyrightconfig.ci.json`:
| File | Errors | Status |
|------|--------|--------|' || '' }}
${{ steps.pyright.outputs.new_files }}
<details>
<summary>Excluded files with errors (${{ steps.excluded.outputs.count }} files)</summary>
These files have known type errors and are excluded from CI. Remove from `pyrightconfig.ci.json` as errors are fixed.
| File | Errors | Status |
|------|--------|--------|
${{ steps.pyright.outputs.excluded_table }}
</details>
- name: Fail if new errors
if: steps.pyright.outputs.has_new_errors == 'true'
run: |
echo "::error::New files with type errors detected! Either fix the errors or add them to pyrightconfig.ci.json"
exit 1