Fixed recent regression that results in assert_type failure when a class is parameterized by a ParamSpec with a default value. This addresses #7878.

This commit is contained in:
Eric Traut 2024-05-12 00:22:58 -07:00
parent 8a5bfb975c
commit da446c7c6a
2 changed files with 13 additions and 5 deletions

View File

@ -12591,13 +12591,11 @@ export function createTypeEvaluator(
}
function getParamSpecDefaultType(node: ExpressionNode, isPep695Syntax: boolean): Type | undefined {
const functionType = FunctionType.createSynthesizedInstance(
'',
FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck | FunctionTypeFlags.ParamSpecValue
);
const functionType = FunctionType.createSynthesizedInstance('', FunctionTypeFlags.ParamSpecValue);
if (node.nodeType === ParseNodeType.Ellipsis) {
FunctionType.addDefaultParameters(functionType);
functionType.details.flags |= FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck;
return functionType;
}

View File

@ -2,7 +2,7 @@
# In particular, it tests the handling of default TypeVar types for
# generic classes.
from typing import Generic, Self
from typing import Generic, Self, assert_type
from typing_extensions import ( # pyright: ignore[reportMissingModuleSource]
TypeVar,
ParamSpec,
@ -117,3 +117,13 @@ reveal_type(
ClassD[int, str, [str, complex]],
expected_text="type[ClassD[int, str, (str, complex), (bool)]]",
)
P6 = ParamSpec("P6", default=[str, int])
class ClassE(Generic[P6]): ...
assert_type(ClassE, type[ClassE[str, int]])
assert_type(ClassE(), ClassE[str, int])
assert_type(ClassE[[bool, bool]](), ClassE[bool, bool])