[ty] Add some additional type safety to CycleDetector#19903
Merged
Conversation
Contributor
Diagnostic diff on typing conformance testsChanges were detected when running ty on typing conformance tests--- old-output.txt 2025-08-13 21:23:19.455742809 +0000
+++ new-output.txt 2025-08-13 21:23:19.524743390 +0000
@@ -1,5 +1,5 @@
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
-fatal[panic] Panicked at /home/runner/.cargo/git/checkouts/salsa-e6f3bb7c2a062968/918d35d/src/function/execute.rs:215:25 when checking `/home/runner/work/ruff/ruff/typing/conformance/tests/aliases_typealiastype.py`: `infer_definition_types(Id(c4bf)): execute: too many cycle iterations`
+fatal[panic] Panicked at /home/runner/.cargo/git/checkouts/salsa-e6f3bb7c2a062968/918d35d/src/function/execute.rs:215:25 when checking `/home/runner/work/ruff/ruff/typing/conformance/tests/aliases_typealiastype.py`: `infer_definition_types(Id(413ae)): execute: too many cycle iterations`
_directives_deprecated_library.py:15:31: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `int`
_directives_deprecated_library.py:30:26: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `str`
_directives_deprecated_library.py:36:41: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `Self@__add__` |
Contributor
|
carljm
approved these changes
Aug 13, 2025
Contributor
carljm
left a comment
There was a problem hiding this comment.
This is great, thank you!
As someone who has added a lot of visitor arguments to methods, and will be adding a lot more, I think I'd really appreciate some type aliases here, so I can say e.g. visitor: &NormalizeVisitor instead of visitor: &TypeTransformer<'db, Normalized>. But not a blocker.
Member
Author
Good idea! Done |
carljm
added a commit
that referenced
this pull request
Aug 13, 2025
* main: [ty] Add some additional type safety to `CycleDetector` (#19903)
dcreager
added a commit
that referenced
this pull request
Aug 14, 2025
* main: Feature/build riscv64 bin (#19819) [ty] Add caching to `CodeGeneratorKind::matches()` (#19912) [ty] Rename `functionArgumentNames` to `callArgumentNames` inlay hint setting (#19911) [ty] Default `ty.inlayHints.*` server settings to true (#19910) [ty] Remove py-fuzzer skips for seeds that are no longer slow (#19906) [ty] fix deferred name loading in PEP695 generic classes/functions (#19888) [ty] Add some additional type safety to `CycleDetector` (#19903) [`flake8-blind-except`] Fix `BLE001` false-positive on `raise ... from None` (#19755) [ty] resolve docstrings for modules (#19898)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a type tag to the
CycleDetectorvisitor (and its aliases).There are some places where we implement e.g. an equivalence check by making a disjointness check. Both
is_equivalent_toandis_disjoint_fromuse aPairVisitorto handle cycles, but they should not use the same visitor. I was finding it tedious to remember when it was appropriate to pass on a visitor and when not to. This adds aPhantomDatatype tag to ensure that we can't pass on one method's visitor to a different method.For
has_relationandapply_type_mapping, we have an existing type that we can use as the tag. For the other methods, I've added empty structs (Normalized,IsDisjointFrom,IsEquivalentTo) to use as tags.