mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:39:12 +00:00
[red-knot] Minor optimization/cleanup in member lookup (#16663)
## Summary A follow up to address [this comment]: > Similarly here, it might be a little more performant to have a single `Type::instance()` branch with an inner match over `class.known()` rather than having multiple branches with `if class.is_known()` guards [this comment]: https://github.com/astral-sh/ruff/pull/16416#discussion_r1985159037
This commit is contained in:
parent
860b95a318
commit
3228545598
1 changed files with 10 additions and 14 deletions
|
@ -1936,7 +1936,7 @@ impl<'db> Type<'db> {
|
|||
.into(),
|
||||
|
||||
Type::ClassLiteral(ClassLiteralType { class })
|
||||
if class.is_known(db, KnownClass::FunctionType) && name == "__get__" =>
|
||||
if name == "__get__" && class.is_known(db, KnownClass::FunctionType) =>
|
||||
{
|
||||
Symbol::bound(Type::Callable(CallableType::WrapperDescriptorDunderGet)).into()
|
||||
}
|
||||
|
@ -1972,20 +1972,16 @@ impl<'db> Type<'db> {
|
|||
}
|
||||
|
||||
Type::Instance(InstanceType { class })
|
||||
if class.is_known(db, KnownClass::VersionInfo) && name == "major" =>
|
||||
if matches!(name.as_str(), "major" | "minor")
|
||||
&& class.is_known(db, KnownClass::VersionInfo) =>
|
||||
{
|
||||
Symbol::bound(Type::IntLiteral(
|
||||
Program::get(db).python_version(db).major.into(),
|
||||
))
|
||||
.into()
|
||||
}
|
||||
Type::Instance(InstanceType { class })
|
||||
if class.is_known(db, KnownClass::VersionInfo) && name == "minor" =>
|
||||
{
|
||||
Symbol::bound(Type::IntLiteral(
|
||||
Program::get(db).python_version(db).minor.into(),
|
||||
))
|
||||
.into()
|
||||
let python_version = Program::get(db).python_version(db);
|
||||
let segment = if name == "major" {
|
||||
python_version.major
|
||||
} else {
|
||||
python_version.minor
|
||||
};
|
||||
Symbol::bound(Type::IntLiteral(segment.into())).into()
|
||||
}
|
||||
|
||||
Type::IntLiteral(_) if matches!(name_str, "real" | "numerator") => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue