-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Discard Definitions when normalizing Signatures
#19615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
Contributor
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
Contributor
|
dcreager
approved these changes
Jul 29, 2025
Member
dcreager
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me!
dcreager
added a commit
that referenced
this pull request
Aug 1, 2025
* main: (24 commits) Add `Checker::context` method, deduplicate Unicode checks (#19609) [`flake8-pyi`] Preserve inline comment in ellipsis removal (`PYI013`) (#19399) [ty] Add flow diagram for import resolution [ty] Add comments to some core resolver functions [ty] Add missing ticks and use consistent quoting [ty] Reflow some long lines [ty] Unexport helper function [ty] Remove offset from `CompletionTargetTokens::Unknown` [`pyupgrade`] Fix `UP030` to avoid modifying double curly braces in format strings (#19378) [ty] fix a typo (#19621) [ty] synthesize `__replace__` for dataclasses (>=3.13) (#19545) [ty] Discard `Definition`s when normalizing `Signature`s (#19615) [ty] Fix empty spans following a line terminator and unprintable character spans in diagnostics (#19535) Add `LinterContext::settings` to avoid passing separate settings (#19608) Support `.pyi` files in ruff analyze graph (#19611) [ty] Sync vendored typeshed stubs (#19607) [ty] Bump docstring-adder pin (#19606) [`perflint`] Ignore rule if target is `global` or `nonlocal` (`PERF401`) (#19539) Add license classifier back to pyproject.toml (#19599) [ty] Add stub mapping support to signature help (#19570) ...
Gankra
pushed a commit
that referenced
this pull request
Aug 21, 2025
## Summary This PR fixes astral-sh/ty#1071 The core issue is that `CallableType` is a salsa interned but `Signature` (which `CallableType` stores) ignores the `Definition` in its `Eq` and `Hash` implementation. This PR tries to simplest fix by removing the custom `Eq` and `Hash` implementation. The main downside of this fix is that it can increase memory usage because `CallableType`s that are equal except for their `Definition` are now interned separately. The alternative is to remove `Definition` from `CallableType` and instead, call `bindings` directly on the callee (call_expression.func). However, this would require addressing the TODO here https://github.com/astral-sh/ruff/blob/39ee71c2a57bd6c51482430ba8bfe3728b4ca443/crates/ty_python_semantic/src/types.rs#L4582-L4586 This might probably be worth addressing anyway, but is the more involved fix. That's why I opted for removing the custom `Eq` implementation. We already "ignore" the definition during normalization, thank's to Alex's work in #19615 ## Test Plan https://github.com/user-attachments/assets/248d1cb1-12fd-4441-adab-b7e0866d23eb
second-ed
pushed a commit
to second-ed/ruff
that referenced
this pull request
Sep 9, 2025
…20021) ## Summary This PR fixes astral-sh/ty#1071 The core issue is that `CallableType` is a salsa interned but `Signature` (which `CallableType` stores) ignores the `Definition` in its `Eq` and `Hash` implementation. This PR tries to simplest fix by removing the custom `Eq` and `Hash` implementation. The main downside of this fix is that it can increase memory usage because `CallableType`s that are equal except for their `Definition` are now interned separately. The alternative is to remove `Definition` from `CallableType` and instead, call `bindings` directly on the callee (call_expression.func). However, this would require addressing the TODO here https://github.com/astral-sh/ruff/blob/39ee71c2a57bd6c51482430ba8bfe3728b4ca443/crates/ty_python_semantic/src/types.rs#L4582-L4586 This might probably be worth addressing anyway, but is the more involved fix. That's why I opted for removing the custom `Eq` implementation. We already "ignore" the definition during normalization, thank's to Alex's work in astral-sh#19615 ## Test Plan https://github.com/user-attachments/assets/248d1cb1-12fd-4441-adab-b7e0866d23eb
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.
Summary
I noticed while looking at some debug prints that we appear to be holding onto the original
Definitionassociated with aSignaturewhen we normalize theSignature. This defeats the point of normalization of types: it means that two equivalentSignatures (and therefore two equivalentCallableTypes) might not share the same Salsa ID even after being normalized if they originated from differentStmtFunctionDefs in the source code.I'm not sure whether or not this would lead to a user-facing bug right now, but it feels like a latent bug waiting to pounce, so this PR fixes it. Fixing the latent bug also has the advantage that it makes the debug representation of normalized
CallableTypes more concise, and probably reduces memory a little bit (because we need to intern fewerSignatures when normalizingCallableTypes). I think there are no downsides to this change: normalized types should usually only be created transitively, so this shouldn't have any impact on goto-definition or go-to type definition.Test Plan
cargo test -p ty_python_semantic