зеркало из https://github.com/microsoft/pyright.git
Fixed recent regression that results in a false positive error when attempting to assign the expression `type(Any)` to type `type[Any]`. This addresses #8973. (#8976)
This commit is contained in:
Родитель
a0ecfe25d6
Коммит
dd3ba0a96a
|
@ -24193,7 +24193,11 @@ export function createTypeEvaluator(
|
|||
|
||||
if (isClassInstance(destType)) {
|
||||
if (ClassType.isBuiltIn(destType, 'type')) {
|
||||
if (isInstantiableClass(srcType) && isSpecialFormClass(srcType, flags)) {
|
||||
if (
|
||||
isInstantiableClass(srcType) &&
|
||||
isSpecialFormClass(srcType, flags) &&
|
||||
TypeBase.getInstantiableDepth(srcType) === 0
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,10 @@ v1 = cast(Any, 0)
|
|||
v2 = cast(typing.Any, 0)
|
||||
|
||||
|
||||
class A(Any):
|
||||
...
|
||||
class A(Any): ...
|
||||
|
||||
|
||||
class B(typing.Any):
|
||||
...
|
||||
class B(typing.Any): ...
|
||||
|
||||
|
||||
# This should generate an error because Any is not callable.
|
||||
|
@ -36,3 +34,12 @@ def func1() -> int:
|
|||
def func2() -> int:
|
||||
# This should generate an error because Any cannot be used as a value.
|
||||
return typing.Any
|
||||
|
||||
|
||||
v3: type[Any] = type(Any)
|
||||
|
||||
# This should generate an error.
|
||||
v4: type[type] = type(Any)
|
||||
|
||||
# This should generate an error.
|
||||
v5: type = Any
|
||||
|
|
|
@ -962,7 +962,7 @@ test('Del2', () => {
|
|||
test('Any1', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['any1.py']);
|
||||
|
||||
TestUtils.validateResults(analysisResults, 6);
|
||||
TestUtils.validateResults(analysisResults, 8);
|
||||
});
|
||||
|
||||
test('Type1', () => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче