-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[red-knot] Distribute intersections on negation #13962
Changes from 2 commits
a324834
8c608c2
e01da82
e7e432b
338692b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ use crate::semantic_index::{ | |
}; | ||
use crate::stdlib::{ | ||
builtins_symbol_ty, types_symbol_ty, typeshed_symbol_ty, typing_extensions_symbol_ty, | ||
typing_symbol_ty, | ||
}; | ||
use crate::types::narrow::narrowing_constraint; | ||
use crate::{Db, FxOrderSet, HasTy, Module, SemanticModel}; | ||
|
@@ -740,7 +741,9 @@ impl<'db> Type<'db> { | |
| KnownClass::Dict | ||
| KnownClass::GenericAlias | ||
| KnownClass::ModuleType | ||
| KnownClass::FunctionType, | ||
| KnownClass::FunctionType | ||
| KnownClass::Sized | ||
| KnownClass::Hashable, | ||
) => false, | ||
None => false, | ||
}, | ||
|
@@ -1132,6 +1135,9 @@ pub enum KnownClass { | |
GenericAlias, | ||
ModuleType, | ||
FunctionType, | ||
// Typing | ||
Sized, | ||
Hashable, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry to catch this only after you'd done the work, but I don't see any reason for these to be known classes? We should only use I don't think If you want to use these types (or any other typeshed type) in tests, you don't need it to be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hadn't quite internalized that I only actually really need |
||
// Typeshed | ||
NoneType, // Part of `types` for Python >= 3.10 | ||
} | ||
|
@@ -1153,6 +1159,8 @@ impl<'db> KnownClass { | |
Self::GenericAlias => "GenericAlias", | ||
Self::ModuleType => "ModuleType", | ||
Self::FunctionType => "FunctionType", | ||
Self::Sized => "Sized", | ||
Self::Hashable => "Hashable", | ||
Self::NoneType => "NoneType", | ||
} | ||
} | ||
|
@@ -1177,6 +1185,8 @@ impl<'db> KnownClass { | |
Self::GenericAlias | Self::ModuleType | Self::FunctionType => { | ||
types_symbol_ty(db, self.as_str()) | ||
} | ||
Self::Sized | Self::Hashable => typing_symbol_ty(db, self.as_str()), | ||
|
||
Self::NoneType => typeshed_symbol_ty(db, self.as_str()), | ||
} | ||
} | ||
|
@@ -1210,6 +1220,8 @@ impl<'db> KnownClass { | |
"NoneType" => Some(Self::NoneType), | ||
"ModuleType" => Some(Self::ModuleType), | ||
"FunctionType" => Some(Self::FunctionType), | ||
"Sized" => Some(Self::Sized), | ||
"Hashable" => Some(Self::Hashable), | ||
_ => None, | ||
} | ||
} | ||
|
@@ -1232,6 +1244,9 @@ impl<'db> KnownClass { | |
| Self::Set | ||
| Self::Dict => module.name() == "builtins", | ||
Self::GenericAlias | Self::ModuleType | Self::FunctionType => module.name() == "types", | ||
Self::Sized | Self::Hashable => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. basically all of the "interesting" protocols in |
||
matches!(module.name().as_str(), "typing" | "collections.abc") | ||
} | ||
Self::NoneType => matches!(module.name().as_str(), "_typeshed" | "types"), | ||
} | ||
} | ||
|
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.