diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 06bdb8b2cc92..e8fe3c2f3ab9 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -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 \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2773300caa3a..eda214b85bc9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/src/prefect/blocks/abstract.py b/src/prefect/blocks/abstract.py index ca29dd04b03e..495eaa67f446 100644 --- a/src/prefect/blocks/abstract.py +++ b/src/prefect/blocks/abstract.py @@ -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 @@ -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] diff --git a/src/prefect/logging/handlers.py b/src/prefect/logging/handlers.py index 7edd7aa14294..58aac2fb633f 100644 --- a/src/prefect/logging/handlers.py +++ b/src/prefect/logging/handlers.py @@ -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 @@ -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 class APILogWorker(BatchedQueueService[Dict[str, Any]]): diff --git a/src/prefect/logging/loggers.py b/src/prefect/logging/loggers.py index 9f8f82f0db1d..3021ccec4e32 100644 --- a/src/prefect/logging/loggers.py +++ b/src/prefect/logging/loggers.py @@ -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