-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[ty] Add KnownUnion::to_type()
#21948
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
Conversation
| 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))), |
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.
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.
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
* 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) ...
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