Merged
Conversation
AlexWaygood
commented
Dec 12, 2025
Comment on lines
-7299
to
7290
| let ty = match class.known(db) { | ||
| Some(KnownClass::Complex) => UnionType::from_elements( | ||
| db, | ||
| [ | ||
| KnownClass::Int.to_instance(db), | ||
| KnownClass::Float.to_instance(db), | ||
| KnownClass::Complex.to_instance(db), | ||
| ], | ||
| ), | ||
| Some(KnownClass::Float) => UnionType::from_elements( | ||
| db, | ||
| [ | ||
| KnownClass::Int.to_instance(db), | ||
| KnownClass::Float.to_instance(db), | ||
| ], | ||
| ), | ||
| _ if class.is_typed_dict(db) => { | ||
| Type::typed_dict(class.default_specialization(db)) | ||
| } | ||
| Some(KnownClass::Complex) => KnownUnion::Complex.to_type(db), | ||
| Some(KnownClass::Float) => KnownUnion::Float.to_type(db), | ||
| _ => Type::instance(db, class.default_specialization(db)), | ||
| }; | ||
| Ok(ty) | ||
| } | ||
| Type::GenericAlias(alias) if alias.is_typed_dict(db) => Ok(Type::typed_dict(*alias)), | ||
| Type::GenericAlias(alias) => Ok(Type::instance(db, ClassType::from(*alias))), |
Member
Author
There was a problem hiding this comment.
whether or not the class is a TypedDict is also checked in the Type::instance() call. Checking whether the class-literal/generic-alias is a TypedDict before calling Type::instance() is redundant.
MichaReiser
approved these changes
Dec 12, 2025
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
dcreager
added a commit
that referenced
this pull request
Dec 13, 2025
* origin/main: (22 commits) [ty] Allow gradual lower/upper bounds in a constraint set (#21957) [ty] disallow explicit specialization of type variables themselves (#21938) [ty] Improve diagnostics for unsupported binary operations and unsupported augmented assignments (#21947) [ty] update implicit root docs (#21955) [ty] Enable even more goto-definition on inlay hints (#21950) Document known lambda formatting deviations from Black (#21954) [ty] fix hover type on named expression target (#21952) Bump benchmark dependencies (#21951) Keep lambda parameters on one line and parenthesize the body if it expands (#21385) [ty] Improve resolution of absolute imports in tests (#21817) [ty] Support `__all__ += submodule.__all__` [ty] Change frequency of invalid `__all__` debug message [ty] Add `KnownUnion::to_type()` (#21948) [ty] Classify `cls` as class parameter (#21944) [ty] Stabilize rename (#21940) [ty] Ignore `__all__` for document and workspace symbol requests [ty] Attach db to background request handler task (#21941) [ty] Fix outdated version in publish diagnostics after `didChange` (#21943) [ty] avoid fixpoint unioning of types containing current-cycle Divergent (#21910) [ty] improve bad specialization results & error messages (#21840) ...
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.
Summary
A small refactor followup to #21886. Now that we have a
KnownUnionenum, we can use it in more places to make our code a bit more DRYTest Plan
pure refactor; no added tests