Skip to content

Commit

Permalink
Move pyright checks to CI (#16843)
Browse files Browse the repository at this point in the history
  • Loading branch information
desertaxle authored Jan 24, 2025
1 parent bb37ef5 commit adddb4a
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 13 deletions.
39 changes: 38 additions & 1 deletion .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,41 @@ jobs:

- name: Run pre-commit
run: |
pre-commit run --show-diff-on-failure --color=always --all-files
pre-commit run --show-diff-on-failure --color=always --all-files
type-checks:
name: Type Checks
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"
enable-cache: true
cache-dependency-glob: "requirements**.txt"

- name: Run type completeness check
run: >-
uv tool run
--with-editable .
--with-requirements requirements-otel.txt
--with-requirements requirements-dev.txt
pyright
--ignoreexternal
--verifytypes prefect
- name: Run pyright check
run: >-
uv tool run
--with-editable .
--with-requirements requirements-otel.txt
--with-requirements requirements-dev.txt
pyright
-p pyrightconfig-ci.json
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ 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
112 changes: 112 additions & 0 deletions pyrightconfig-ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"include": ["src/"],

"typeCheckingMode": "standard",
"strictListInference": true,
"strictDictionaryInference": true,
"strictSetInference": true,
"reportMissingTypeStubs": "error",
"reportAssertAlwaysTrue": "error",
"reportInvalidStringEscapeSequence": "error",
"reportInvalidTypeVarUse": "error",
"reportSelfClsParameterName": "error",
"reportUnsupportedDunderAll": "error",
"reportUnusedExpression": "error",
"reportWildcardImportFromLibrary": "error",
"reportConstantRedefinition": "error",
"reportDeprecated": "error",
"reportDuplicateImport": "error",
"reportIncompleteStub": "error",
"reportInconsistentConstructor": "error",
"reportMatchNotExhaustive": "error",
"reportMissingParameterType": "error",
"reportMissingTypeArgument": "error",
"reportPrivateUsage": "error",
"reportTypeCommentUsage": "error",
"reportUnnecessaryCast": "error",
"reportUnnecessaryComparison": "error",
"reportUnnecessaryContains": "error",
"reportUnnecessaryIsInstance": "error",
"reportUnusedClass": "error",
"reportUnusedImport": "error",
"reportUnusedFunction": "error",
"reportUnusedVariable": "error",
"reportUntypedBaseClass": "error",
"reportUntypedClassDecorator": "error",
"reportUntypedFunctionDecorator": "error",
"reportUntypedNamedTuple": "error",
"reportUnknownArgumentType": "warning",
"reportUnknownLambdaType": "warning",
"reportUnknownMemberType": "warning",
"reportUnknownParameterType": "warning",
"reportUnknownVariableType": "warning",

"strict": [],

"ignore": [
"src/prefect/_version.py",
"src/prefect/server/database/_migrations/",
"src/integrations/",
"src/prefect/_experimental/",
"src/prefect/_internal/compatibility/async_dispatch.py",
"src/prefect/_internal/compatibility/deprecated.py",
"src/prefect/_internal/concurrency/inspection.py",
"src/prefect/_internal/concurrency/waiters.py",
"src/prefect/_internal/pydantic/annotations/pendulum.py",
"src/prefect/_internal/schemas/validators.py",
"src/prefect/_internal/_logging.py",
"src/prefect/_internal/pytz.py",
"src/prefect/_internal/retries.py",
"src/prefect/blocks/",
"src/prefect/cli/",
"src/prefect/deployments/",
"src/prefect/docker/",
"src/prefect/events/",
"src/prefect/infrastructure/",
"src/prefect/input/",
"src/prefect/locking/",
"src/prefect/logging/",
"src/prefect/records/",
"src/prefect/runner/",
"src/prefect/runtime/",
"src/prefect/settings/",
"src/prefect/server/api/",
"src/prefect/server/events/",
"src/prefect/server/models/",
"src/prefect/server/orchestration/",
"src/prefect/server/schemas/",
"src/prefect/server/services/",
"src/prefect/server/utilities/messaging/",
"src/prefect/server/utilities/encryption.py",
"src/prefect/server/utilities/server.py",
"src/prefect/server/task_queue.py",
"src/prefect/telemetry/processors.py",
"src/prefect/telemetry/services.py",
"src/prefect/testing/",
"src/prefect/types/__init__.py",
"src/prefect/workers/__init__.py",
"src/prefect/workers/base.py",
"src/prefect/workers/process.py",
"src/prefect/artifacts.py",
"src/prefect/automations.py",
"src/prefect/context.py",
"src/prefect/engine.py",
"src/prefect/filesystems.py",
"src/prefect/flow_engine.py",
"src/prefect/flow_runs.py",
"src/prefect/flows.py",
"src/prefect/futures.py",
"src/prefect/plugins.py",
"src/prefect/results.py",
"src/prefect/states.py",
"src/prefect/task_engine.py",
"src/prefect/task_runners.py",
"src/prefect/task_runs.py",
"src/prefect/task_worker.py",
"src/prefect/tasks.py",
"src/prefect/transactions.py",
"tests/",
"client/"
],
"reportUnnecessaryTypeIgnoreComments": true
}
2 changes: 1 addition & 1 deletion src/prefect/_internal/concurrency/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def start(self) -> None:
# failure to process items. This is particularly relevant for services
# which use an httpx client. See related issue at
# https://github.com/python/cpython/issues/86813
threading._register_atexit(self._at_exit) # pyright: ignore[reportUnknownVariableType, reportAttributeAccessIssue]
threading._register_atexit(self._at_exit) # pyright: ignore[reportUnknownMemberType, reportAttributeAccessIssue]

def _at_exit(self) -> None:
self.drain(at_exit=True)
Expand Down
8 changes: 4 additions & 4 deletions src/prefect/client/schemas/schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class CronSchedule(PrefectBaseModel):

@field_validator("timezone")
@classmethod
def valid_timezone(cls, v: Optional[str]) -> str:
def valid_timezone(cls, v: Optional[str]) -> Optional[str]:
return default_timezone(v)

@field_validator("cron")
Expand Down Expand Up @@ -276,7 +276,7 @@ def to_rrule(self) -> Union[dateutil.rrule.rrule, dateutil.rrule.rruleset]:
kwargs.update(
until=until.replace(tzinfo=timezone),
)
return rrule.replace(**kwargs)
return rrule.replace(**kwargs) # pyright: ignore[reportUnknownVariableType, reportUnknownMemberType] missing type hints

# update rrules
localized_rrules: list[dateutil.rrule.rrule] = []
Expand All @@ -286,7 +286,7 @@ def to_rrule(self) -> Union[dateutil.rrule.rrule, dateutil.rrule.rruleset]:
kwargs: dict[str, Any] = dict(dtstart=dtstart.replace(tzinfo=timezone))
if until := _rrule_dt(rr, "_until"):
kwargs.update(until=until.replace(tzinfo=timezone))
localized_rrules.append(rr.replace(**kwargs))
localized_rrules.append(rr.replace(**kwargs)) # pyright: ignore[reportUnknownArgumentType, reportUnknownMemberType] missing type hints
setattr(rrule, "_rrule", localized_rrules)

# update exrules
Expand All @@ -297,7 +297,7 @@ def to_rrule(self) -> Union[dateutil.rrule.rrule, dateutil.rrule.rruleset]:
kwargs = dict(dtstart=dtstart.replace(tzinfo=timezone))
if until := _rrule_dt(exr, "_until"):
kwargs.update(until=until.replace(tzinfo=timezone))
localized_exrules.append(exr.replace(**kwargs))
localized_exrules.append(exr.replace(**kwargs)) # pyright: ignore[reportUnknownArgumentType, reportUnknownMemberType] missing type hints
setattr(rrule, "_exrule", localized_exrules)

# update rdates
Expand Down
2 changes: 1 addition & 1 deletion src/prefect/server/utilities/schemas/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,4 @@ class ORMBaseModel(IDBaseModel):


class ActionBaseModel(PrefectBaseModel):
model_config: ConfigDict = ConfigDict(extra="forbid")
model_config: ClassVar[ConfigDict] = ConfigDict(extra="forbid")
2 changes: 1 addition & 1 deletion src/prefect/utilities/render_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def swagger_lib(config: MkDocsConfig) -> dict[str, Any]:
}

extra_javascript = config.extra_javascript
extra_css = cast(list[str], config.extra_css)
extra_css = cast(list[str], config.extra_css) # pyright: ignore[reportUnknownMemberType] incomplete type hint
for lib in extra_javascript:
if (
os.path.basename(urllib.parse.urlparse(str(lib)).path)
Expand Down
7 changes: 7 additions & 0 deletions src/prefect/utilities/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ def apply_values(
...


@overload
def apply_values(
template: T, values: dict[str, Any], remove_notset: bool = False
) -> Union[T, type[NotSet]]:
...


def apply_values(
template: T, values: dict[str, Any], remove_notset: bool = True
) -> Union[T, type[NotSet]]:
Expand Down

0 comments on commit adddb4a

Please # to comment.