Skip to content
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

Fixed a bug that resulted in an incorrect type evaluation when access… #6419

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5904,7 +5904,11 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
// generic but are not defined that way. Because of this, we use type variables
// in the synthesized methods (e.g. __get__) for the property class that are
// defined in the class that declares the fget method.
const specializedType = partiallySpecializeType(methodType, memberInfo.classType, classType);
const specializedType = partiallySpecializeType(
methodType,
memberInfo.classType,
selfType ? (convertToInstantiable(selfType) as ClassType | TypeVarType) : classType
);
if (isFunction(specializedType) || isOverloadedFunction(specializedType)) {
methodType = specializedType;
}
Expand Down
19 changes: 18 additions & 1 deletion packages/pyright-internal/src/tests/samples/property1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# properties.


from typing import Self


class ClassA:
@property
def read_only_prop(self):
Expand Down Expand Up @@ -66,7 +69,7 @@ def deletable_prop(self):
del a.deletable_prop


class ClassWithProperty:
class ClassB:
@property
def name(self) -> str:
return "bar"
Expand All @@ -75,3 +78,17 @@ def name(self) -> str:
p1: property = ClassA.read_only_prop
p2: property = ClassA.read_write_prop
p3: property = ClassA.deletable_prop


class ClassC:
@property
def prop1(self) -> type[Self]:
...

def method1(self) -> None:
reveal_type(self.prop1, expected_text="type[Self@ClassC]")


class ClassD(ClassC):
def method1(self) -> None:
reveal_type(self.prop1, expected_text="type[Self@ClassD]")