Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 1 addition & 60 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,63 +66,4 @@ jobs:

- name: Run pre-commit
run: |
pre-commit run --show-diff-on-failure --color=always --all-files

type-completeness-check:
name: Type completeness check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0

- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
python-version: "3.12"

- name: Calculate type completeness score
id: calculate_current_score
run: |
# `pyright` will exit with a non-zero status code if it finds any issues,
# so we need to explicitly ignore the exit code with `|| true`.
uv tool run --with-editable . pyright --verifytypes prefect --ignoreexternal --outputjson > prefect-analysis.json || true
SCORE=$(jq -r '.typeCompleteness.completenessScore' prefect-analysis.json)
echo "current_score=$SCORE" >> $GITHUB_OUTPUT

- name: Checkout base branch
run: |
git checkout ${{ github.base_ref }}

- name: Calculate base branch score
id: calculate_base_score
run: |
uv tool run --with-editable . pyright --verifytypes prefect --ignoreexternal --outputjson > prefect-analysis-base.json || true
BASE_SCORE=$(jq -r '.typeCompleteness.completenessScore' prefect-analysis-base.json)
echo "base_score=$BASE_SCORE" >> $GITHUB_OUTPUT

- name: Compare scores
run: |
CURRENT_SCORE=$(echo ${{ steps.calculate_current_score.outputs.current_score }})
BASE_SCORE=$(echo ${{ steps.calculate_base_score.outputs.base_score }})

if (( $(echo "$BASE_SCORE > $CURRENT_SCORE" | bc -l) )); then
echo "::notice title=Type Completeness Check::We noticed a decrease in type coverage with these changes. Check workflow summary for more details."
echo "### ℹ️ Type Completeness Check" >> $GITHUB_STEP_SUMMARY
echo "We noticed a decrease in type coverage with these changes. To maintain our codebase quality, we aim to keep or improve type coverage with each change." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Need help? Ping @desertaxle or @zzstoatzz for assistance!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Here's what changed:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
uv run scripts/pyright_diff.py prefect-analysis-base.json prefect-analysis.json >> $GITHUB_STEP_SUMMARY
SCORE_DIFF=$(echo "$BASE_SCORE - $CURRENT_SCORE" | bc -l)
if (( $(echo "$SCORE_DIFF > 0.001" | bc -l) )); then
exit 1
fi
elif (( $(echo "$BASE_SCORE < $CURRENT_SCORE" | bc -l) )); then
echo "🎉 Great work! The type coverage has improved with these changes" >> $GITHUB_STEP_SUMMARY
else
echo "✅ Type coverage maintained" >> $GITHUB_STEP_SUMMARY
fi
pre-commit run --show-diff-on-failure --color=always --all-files
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ repos:
)$
- repo: local
hooks:
- id: type-completeness-check
name: Type Completeness Check
language: system
entry: uv run --with pyright pyright --ignoreexternal --verifytypes prefect
pass_filenames: false
- id: generate-mintlify-openapi-docs
name: Generating OpenAPI docs for Mintlify
language: system
Expand Down
7 changes: 5 additions & 2 deletions src/prefect/blocks/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Union,
)

from typing_extensions import Self, TypeAlias
from typing_extensions import TYPE_CHECKING, Self, TypeAlias

from prefect.blocks.core import Block
from prefect.exceptions import MissingContextError
Expand All @@ -26,7 +26,10 @@
if sys.version_info >= (3, 12):
LoggingAdapter = logging.LoggerAdapter[logging.Logger]
else:
LoggingAdapter = logging.LoggerAdapter
if TYPE_CHECKING:
LoggingAdapter = logging.LoggerAdapter[logging.Logger]
else:
LoggingAdapter = logging.LoggerAdapter

LoggerOrAdapter: TypeAlias = Union[Logger, LoggingAdapter]

Expand Down
7 changes: 5 additions & 2 deletions src/prefect/logging/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import uuid
import warnings
from contextlib import asynccontextmanager
from typing import Any, Dict, List, TextIO, Type
from typing import TYPE_CHECKING, Any, Dict, List, TextIO, Type

import pendulum
from rich.console import Console
Expand Down Expand Up @@ -39,7 +39,10 @@
if sys.version_info >= (3, 12):
StreamHandler = logging.StreamHandler[TextIO]
else:
StreamHandler = logging.StreamHandler
if TYPE_CHECKING:
StreamHandler = logging.StreamHandler[TextIO]
else:
StreamHandler = logging.StreamHandler
Comment on lines +42 to +45
Copy link
Member Author

Choose a reason for hiding this comment

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

Added this to ensure the type completeness check is consistent across versions.



class APILogWorker(BatchedQueueService[Dict[str, Any]]):
Expand Down
5 changes: 4 additions & 1 deletion src/prefect/logging/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
if sys.version_info >= (3, 12):
LoggingAdapter = logging.LoggerAdapter[logging.Logger]
else:
LoggingAdapter = logging.LoggerAdapter
if TYPE_CHECKING:
LoggingAdapter = logging.LoggerAdapter[logging.Logger]
else:
LoggingAdapter = logging.LoggerAdapter

if TYPE_CHECKING:
from prefect.client.schemas import FlowRun as ClientFlowRun
Expand Down
Loading