Repository navigation
tentative migrate pyright to ty - #6465
benedikt-bartscher wants to merge 72 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.
Older sqlmodel defines SQLModelConfig twice behind IS_PYDANTIC_V2, so calling it fails ty at the minimum versions although it works at runtime.
The lock keeps ty at 0.0.73. The branch lists ty in backend_pinned, so it is bumped on its own cadence; upstream's dependency refresh moved it to 0.0.88, which reports several hundred new diagnostics, among them every EventHandler[...] annotation now as invalid-type-form. The pydantic Field overload is split into optional-first and required overloads like upstream's other object overloads, so an optional pydantic field reads as ObjectVar[Model]; tests/type_checking/fields.py covers it. The restored set literal in figure_out_type and a new ForwardRef test parameter get invalid-type-form ignores, two new pyright ignores that ty flags become ty ignores, and ignores made unused by the optional object field fix are dropped.
…ainst The published reflex-base 0.10.1a1 alpha, from a release branch not merged here, lacks this PR's UnionType overloads of passthrough_event_spec, so the min-deps check resolved to it.
_STORAGE_FEATURE is typed dict[type, FeatureName], so the lookup needs no runtime narrowing.
A computed var whose deps hold both the current-state placeholder and its explicit full name, as add_dependency on its own state produces, kept only one of the two sets, so a dependency map rebuilt on reload stopped refreshing on the other.
The connection toaster builds ToastProps with only some fields, which type-checks only against the sonner that gives the rest None defaults.
The lock keeps ty at 0.0.73, as in the previous merge, and drops pyright again. Upstream's pyright hooks over tests/type_checking at Python 3.11 and 3.14 become a ty hook at 3.11 beside the existing 3.14 one. Upstream's new pyright ignores are dropped, or become ty ignores where ty flags the same line; the alembic env.py template keeps its pyright ignore, since it is copied into user projects. The optional Field overloads for sequences and sets are split like the list ones, so ty reads rx.Field[set[str] | None] as a SetVar. ClientStateVar.retrieve, now in reflex_base, takes EventType[Any] as the experimental one did, and its test handler is decorated with @rx.event, as is the backend-error handler of the migrated exception handler test. sqlalchemy.inspect passes raiseerr=True so ty reads a mapper, redundant casts are dropped, and the new set operations, the empty-array guard and figure_out_type's set and mapping forms get ignores like their neighbours. reflex-components-internal floors reflex-base on 0.11.1.dev0: the released 0.11.0 still lacks this PR's UnionType overloads of passthrough_event_spec.
|
Hi thank you for this. |
# Conflicts: # packages/reflex-base/src/reflex_base/vars/base.py # tests/units/test_state.py
…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.
| item_var_datas = [] | ||
| for responsive_item in responsive_list: | ||
| if isinstance(responsive_item, dict): | ||
| if not isinstance(responsive_item, Var) and isinstance(responsive_item, dict): |
There was a problem hiding this comment.
convert_list() now checks every item against Var before checking dict. The supported Var classes are not dictionaries, so this adds work without changing which branch runs. The repository guide forbids runtime checks that work around type-only problems. Restore the dictionary-only check before merging to satisfy that requirement.
| if not isinstance(responsive_item, Var) and isinstance(responsive_item, dict): | |
| if isinstance(responsive_item, dict): |
Context Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
_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.
Uh oh!
There was an error while loading. Please reload this page.