Skip to content

Commit 611cbb3

Browse files
committed
fix to_meta_type to fix the member/method resoution panic
1 parent f3b6c67 commit 611cbb3

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

crates/ty_python_semantic/resources/mdtest/annotations/new_types.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ g(Bar(Foo(42)))
5353
h(42) # error: [invalid-argument-type] "Argument to function `h` is incorrect: Expected `Bar`, found `Literal[42]`"
5454
h(Foo(42)) # error: [invalid-argument-type] "Argument to function `h` is incorrect: Expected `Bar`, found `Foo`"
5555
h(Bar(Foo(42)))
56+
57+
# Method lookup works.
58+
def _(x: Bar):
59+
reveal_type(x.bit_length()) # revealed: int
5660
```
5761

5862
## The name must be a string literal

crates/ty_python_semantic/src/types.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6748,9 +6748,7 @@ impl<'db> Type<'db> {
67486748
// understand a more specific meta type in order to correctly handle `__getitem__`.
67496749
Type::TypedDict(typed_dict) => SubclassOfType::from(db, typed_dict.defining_class()),
67506750
Type::TypeAlias(alias) => alias.value_type(db).to_meta_type(db),
6751-
Type::NewTypeInstance(newtype) => {
6752-
Type::KnownInstance(KnownInstanceType::NewType(newtype))
6753-
}
6751+
Type::NewTypeInstance(newtype) => Type::from(newtype.base_class_type(db)),
67546752
}
67556753
}
67566754

0 commit comments

Comments
 (0)