[ty] Stop testing the (brittle) constraint set display implementation#21743
[ty] Stop testing the (brittle) constraint set display implementation#21743
Conversation
| ast::CmpOp::Eq => Some( | ||
| left.constraints(self.db()).iff(self.db(), right.constraints(self.db())) | ||
| ), | ||
| ast::CmpOp::NotEq => Some( | ||
| left.constraints(self.db()).iff(self.db(), right.constraints(self.db())).negate(self.db()) | ||
| ), |
There was a problem hiding this comment.
This is an important bit that lets us replace all of the reveal_type tests with static_asserts. The ConstraintSet.__eq__ implementation now checks whether two constraint sets are equivalent, not whether they are identical.
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
There was a problem hiding this comment.
Thank you!
I guess the major drawback of this is that static_assert will only give you a success/failure feedback, whereas a failing reveal_type tests gives you both display representations (one in the error message, one in the test assertion).
We could follow the route of many other test frameworks and introduce something like a static_assert_eq(left, right) function that would show the display representation of the types of both arguments in case of a failure. That might be even nicer than reveal_type tests because we could properly align the left and right hand side types in the terminal.
I'll merge this PR to unblock the typeshed update. (no, that was the other PR)
The other PR was blocked on this one, though, so thank you regardless!
That's a good idea, I opened astral-sh/ty#1719 to track it. |
* origin/main: (67 commits) Move `Token`, `TokenKind` and `Tokens` to `ruff-python-ast` (#21760) [ty] Don't confuse multiple occurrences of `typing.Self` when binding bound methods (#21754) Use our org-wide Renovate preset (#21759) Delete `my-script.py` (#21751) [ty] Move `all_members`, and related types/routines, out of `ide_support.rs` (#21695) [ty] Fix find-references for import aliases (#21736) [ty] add tests for workspaces (#21741) [ty] Stop testing the (brittle) constraint set display implementation (#21743) [ty] Use generator over list comprehension to avoid cast (#21748) [ty] Add a diagnostic for prohibited `NamedTuple` attribute overrides (#21717) [ty] Fix subtyping with `type[T]` and unions (#21740) Use `npm ci --ignore-scripts` everywhere (#21742) [`flake8-simplify`] Fix truthiness assumption for non-iterable arguments in tuple/list/set calls (`SIM222`, `SIM223`) (#21479) [`flake8-use-pathlib`] Mark fixes unsafe for return type changes (`PTH104`, `PTH105`, `PTH109`, `PTH115`) (#21440) [ty] Fix auto-import code action to handle pre-existing import Enable PEP 740 attestations when publishing to PyPI (#21735) [ty] Fix find references for type defined in stub (#21732) Use OIDC instead of codspeed token (#21719) [ty] Exclude `typing_extensions` from completions unless it's really available [ty] Fix false positives for `class F(Generic[*Ts]): ...` (#21723) ...
The
Displayimplementation for constraint sets is brittle, and deserves a rethink. But later! It's perfectly fine for printf debugging; we just shouldn't be writing mdtests that depend on any particular rendering details. Most of these tests can be replaced with an equivalence check that actually validates that the behavior of two constraint sets are identical.