Fixed bug that causes a "bare" type (with no type argument) or type[Any] to be treated as a possible descriptor object. This addresses #8136. (#8138)

This commit is contained in:
Eric Traut 2024-06-13 08:56:09 -07:00 committed by GitHub
parent 5cb16fe7e4
commit 093e74aa6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -2239,7 +2239,7 @@ export function createTypeEvaluator(
// If this is a type[Any] or type[Unknown], allow any other members.
if (isClassInstance(objectType) && ClassType.isBuiltIn(objectType, 'type') && objectType.includeSubclasses) {
if ((flags & MemberAccessFlags.SkipTypeBaseClass) === 0) {
if ((flags & (MemberAccessFlags.SkipTypeBaseClass | MemberAccessFlags.SkipAttributeAccessOverride)) === 0) {
const typeArg =
objectType.typeArguments && objectType.typeArguments.length >= 1
? objectType.typeArguments[0]

View File

@ -124,3 +124,12 @@ def func7(v: type):
class Class1(Generic[T]):
def method1(self, v: type) -> type[T]:
return v
class Class2:
x1: type
x2: type[Any]
reveal_type(Class2.x1, expected_text="type")
reveal_type(Class2.x2, expected_text="type[Any]")