Repository navigation
tentative migrate pyright to ty - #6465
benedikt-bartscher wants to merge 79 commits into
Conversation
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
Resolve conflicts from upstream's memo refactor (reflex-dev#6517, promote rx._x.memo to rx.memo): memo implementation moved to reflex_base.components.memo and CustomComponent was removed. Re-apply the ty migration changes onto the new locations: - reflex/experimental/memo.py: take upstream's deprecated alias - reflex_base/components/memo.py: type fn params as FunctionType and add ty:ignore for dynamic __signature__ assignment - tests: drop CustomComponent tests removed upstream; carry ty:ignore comments onto the relocated memo/telemetry tests - pyproject.toml / uv.lock: keep both towncrier (upstream) and ty (HEAD) - pyi_hashes.json: regenerated ty check, ruff, and the unit suite pass.
…ents - Cast redis srem the way the other redis calls in the file are cast, so the lock cleanup type-checks against the declared redis floor as well. - Type the alembic configure kwargs as Any; ty ignores the pyright comment. - Floor reflex-components-dataeditor on the reflex-base with the union passthrough_event_spec overloads. - Return FIELD_TYPE from the component field() again, so a default of the wrong type for a prop is a type error. - Declare ToOperation's fields and constructor for type checkers only instead of making the mixin a runtime dataclass. - Copy a mixin's computed var with a cast instead of skipping a non-function fget, and drop the unreachable branch in Match._validate_return_types. - Add news fragments for every package the migration touches.
The calls in test_model.py that must fail type checking were held to that by pyright's unnecessary-ignore report, which no longer ran. ty catches only some of them: it does not compare an attribute retyped in a subclass, binds an unannotated self in a step to Unknown, and solves wait_for's contravariant workflow to an intersection. Report unused ty ignores in that file, put the pyright ignores back beside the ty ones, and run pyright over the file in pre-commit for the calls only it catches.
ty keeps the calls it catches failing through the unused-ignore rule on this file. The ones it misses (a column retyped in a subclass, astral-sh/ty#2158; a step or wait of another workflow) are rejected by the engine at runtime and covered by the tests of resolve and of the engine's columns, so no second type checker runs in CI. Their pyright ignores stay for anyone who runs pyright.
ty infers no return type for an unannotated function, so the step returning a number was a check of pyright's inference only. Annotated, it checks the type of step itself, and both checkers reject it. Say why the remaining pyright-only calls are: a step or wait mixing two workflows is well-typed under the contravariant workflow parameter, and the redeclared columns need a ty with attribute override checks.
- Rename the rules ty renamed, in the config and in ignore comments, and drop the ignores ty no longer needs. - Spell the event triggers of the bundled components Annotated[EventHandler, spec], the object EventHandler[spec] already evaluates to: ty rejects subscripting a class that is not generic in a type expression (astral-sh/ty#3388). Tests keep the public EventHandler[spec] spelling, with an ignore, as do the pyi generator's fixtures. This lets the repo drop its global not-subscriptable and unsupported-base ignores. - Put HybridProperty.var's callable overload first: ty reads a @classmethod in a class body as a function, and solved the classmethod overload to Unknown. The staticmethod overload is covered by the callable one. - Annotate generator-based context managers as Generator/AsyncGenerator, which typeshed now asks for. - Fix the overrides ty now checks where the fix is local: plotly tags assigned like every other component's, Element.__eq__ named like its base, the model config built as SQLModelConfig. Ignore the rest precisely. - ty now checks attribute overrides, so the workflow model's redeclared engine columns are ty ignores too, kept failing by the unused-ignore rule. - ty fails on warnings now; drop a hosting CLI guard that was always true.
test_check_min_deps still asserted the pre-rename rule name. SQLModelConfig is defined per pydantic version at the declared sqlmodel minimum, so calling it does not type-check there; keep the plain dict with an ignore, as before.
|
What's still open after my pushes:
|
Style keeps keys whose values are dicts, so rx.Style({rx.el.div: {...}})
as App.style carries per-component styles that the early return skipped.
_request is called with unions such as `ManagedDatabase | _NoDatabase`, which are type forms but not instances of `type`, so `cast: type[T]` matched no overload and every such call needed a ty:ignore. Annotating it as `TypeForm[T]` (PEP 747, imported only for type checking since the SDK has no runtime dependencies) lets ty infer the decoded union and drops all 16 ignores.
CachedVarOperation is a plain class, so its cached_property attribute is writable as far as a type checker can tell, while every class mixing it in is a frozen dataclass whose override is read-only. ty rightly reported each override as a read-only attribute overriding a writable one. A type-checking-only property declaration states the attribute's real, read-only type, keeps the runtime body checked and drops all 10 ignores.
Read the handler function from event_handlers and install the partial with monkeypatch.setattr instead of assigning over the class attribute under an ignore, so this test matches the port in reflex-dev#6722 and the change is restored after the test.
The ty hook already checks tests/type_checking under Python 3.11: the project's ty check includes the directory and takes its Python version from the requires-python floor, not the running interpreter, and it runs on every commit that changes a Python file. Keep only the 3.14 re-check and describe the remaining hooks in the type_checking README.
A commit that changes no .py file, like a dependency bump, skipped the full type check, and with it the Python 3.11 check of tests/type_checking.
ty narrows str | dict | Var to dict on the dict check alone now, so the extra isinstance call per responsive item only cost time.
The handlers must accept str | list[str], and ty keeps list[str] after the membership check (astral-sh/ty#5082), so the assignment is ignored instead of narrowed by an extra isinstance call.
The wrapper called callable_name on every var operation it built.
There was a problem hiding this comment.
1 issue found across 404 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/reflex-components-internal/pyproject.toml">
<violation number="1" location="packages/reflex-components-internal/pyproject.toml:20">
P2: This dev floor cannot pass the internal package's release path: `reflex-components-internal` is auto-published, but its publish workflow does not materialize dependency pins and it has no lockstep sibling to rewrite this requirement. Re-pin to a published `reflex-base` version before publishing, or add equivalent release-time rewriting for this package.</violation>
</file>
Note: This PR contains a large number of files. cubic selects up to 200 of the highest-priority eligible files for this review, so some files may not have been reviewed.
View guided diff | Re-trigger cubic
| ] | ||
| dependencies = [ | ||
| "reflex >= 0.11.0", | ||
| "reflex-base >= 0.11.1.dev0", |
There was a problem hiding this comment.
P2: This dev floor cannot pass the internal package's release path: reflex-components-internal is auto-published, but its publish workflow does not materialize dependency pins and it has no lockstep sibling to rewrite this requirement. Re-pin to a published reflex-base version before publishing, or add equivalent release-time rewriting for this package.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/reflex-components-internal/pyproject.toml, line 20:
<comment>This dev floor cannot pass the internal package's release path: `reflex-components-internal` is auto-published, but its publish workflow does not materialize dependency pins and it has no lockstep sibling to rewrite this requirement. Re-pin to a published `reflex-base` version before publishing, or add equivalent release-time rewriting for this package.</comment>
<file context>
@@ -17,6 +17,7 @@ classifiers = [
]
dependencies = [
"reflex >= 0.11.0",
+ "reflex-base >= 0.11.1.dev0",
]
</file context>
A page callable without a __name__ (a functools.partial, an instance with __call__) took its repr as the route name, and failed route validation with that repr in the message. It now takes the no-route path and raises RouteValueError asking for an explicit route.
Uh oh!
There was an error while loading. Please reload this page.