mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Fixed bug that resulted in a false positive error when an abstract class is used for a NewType
and the new type is constructed. This addresses #8256.
This commit is contained in:
parent
353a17cdec
commit
8a9ba9b77b
@ -13006,14 +13006,12 @@ export function createTypeEvaluator(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let classFlags = baseClass.details.flags & ~(ClassTypeFlags.BuiltInClass | ClassTypeFlags.SpecialBuiltIn);
|
|
||||||
classFlags |= ClassTypeFlags.Final | ClassTypeFlags.NewTypeClass | ClassTypeFlags.ValidTypeAliasClass;
|
|
||||||
const classType = ClassType.createInstantiable(
|
const classType = ClassType.createInstantiable(
|
||||||
className,
|
className,
|
||||||
ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className),
|
ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className),
|
||||||
fileInfo.moduleName,
|
fileInfo.moduleName,
|
||||||
fileInfo.fileUri,
|
fileInfo.fileUri,
|
||||||
classFlags,
|
ClassTypeFlags.Final | ClassTypeFlags.NewTypeClass | ClassTypeFlags.ValidTypeAliasClass,
|
||||||
ParseTreeUtils.getTypeSourceId(errorNode),
|
ParseTreeUtils.getTypeSourceId(errorNode),
|
||||||
/* declaredMetaclass */ undefined,
|
/* declaredMetaclass */ undefined,
|
||||||
baseClass.details.effectiveMetaclass
|
baseClass.details.effectiveMetaclass
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# This sample tests the type handler's handling of the
|
# This sample tests the type handler's handling of the
|
||||||
# built-in NewType function.
|
# built-in NewType function.
|
||||||
|
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
from typing import Any, NewType, TypeVar, TypedDict
|
from typing import Any, NewType, TypeVar, TypedDict
|
||||||
|
|
||||||
MyString = NewType("MyString", "str")
|
MyString = NewType("MyString", "str")
|
||||||
@ -76,3 +77,17 @@ def func2(x: MyString):
|
|||||||
# with a NewType.
|
# with a NewType.
|
||||||
if issubclass(type(x), (MyString, int)):
|
if issubclass(type(x), (MyString, int)):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class AbstractBase(ABC):
|
||||||
|
@abstractmethod
|
||||||
|
def method1(self, /) -> int: ...
|
||||||
|
|
||||||
|
|
||||||
|
class DerivedBase(AbstractBase):
|
||||||
|
def method1(self, /) -> int:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
NewDerived = NewType("NewDerived", AbstractBase)
|
||||||
|
new_derived = NewDerived(DerivedBase())
|
||||||
|
Loading…
Reference in New Issue
Block a user