mirror of
https://github.com/microsoft/pyright.git
synced 2024-10-26 10:55:06 +03:00
Changed the behavior when invoking constructor for type[T]
where T
is a TypeVar with no explicit upper bound (and therefore has an implicit upper bound of object
). According to the newly-clarified typing spec, this should enforce the constructor signature of object
. (#7697)
This commit is contained in:
parent
7f46092aef
commit
9d87fe1079
@ -637,7 +637,6 @@ function validateFallbackConstructorCall(
|
||||
|
||||
// It's OK if the argument list consists only of `*args` and `**kwargs`.
|
||||
if (argList.length > 0 && argList.some((arg) => arg.argumentCategory === ArgumentCategory.Simple)) {
|
||||
if (!type.includeSubclasses) {
|
||||
evaluator.addDiagnostic(
|
||||
DiagnosticRule.reportCallIssue,
|
||||
LocMessage.constructorNoArgs().format({ type: type.aliasName || type.details.name }),
|
||||
@ -645,7 +644,6 @@ function validateFallbackConstructorCall(
|
||||
);
|
||||
reportedErrors = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!inferenceContext && type.typeArguments) {
|
||||
// If there was no expected type but the type was already specialized,
|
||||
|
@ -11,5 +11,7 @@ class Foo(Generic[T]):
|
||||
val = self.method1()
|
||||
reveal_type(val(), expected_text="T@Foo")
|
||||
|
||||
def method1(self) -> type[T]:
|
||||
...
|
||||
# This should generate an error.
|
||||
val(1)
|
||||
|
||||
def method1(self) -> type[T]: ...
|
||||
|
@ -13,7 +13,7 @@ T_A = TypeVar("T_A", bound=ClassA)
|
||||
|
||||
|
||||
def func1(cls: type[T_A]) -> T_A:
|
||||
# This should generate an error
|
||||
# This should generate an error.
|
||||
y = cls()
|
||||
|
||||
x = cls(1, "")
|
||||
@ -25,6 +25,7 @@ _T = TypeVar("_T")
|
||||
|
||||
|
||||
def func2(cls: type[_T]) -> _T:
|
||||
# This should generate an error.
|
||||
y = cls(1, "")
|
||||
|
||||
x = cls()
|
||||
|
@ -1572,7 +1572,7 @@ test('Constructor12', () => {
|
||||
test('Constructor13', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['constructor13.py']);
|
||||
|
||||
TestUtils.validateResults(analysisResults, 0);
|
||||
TestUtils.validateResults(analysisResults, 1);
|
||||
});
|
||||
|
||||
test('Constructor14', () => {
|
||||
@ -1620,7 +1620,7 @@ test('Constructor20', () => {
|
||||
test('Constructor21', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['constructor21.py']);
|
||||
|
||||
TestUtils.validateResults(analysisResults, 1);
|
||||
TestUtils.validateResults(analysisResults, 2);
|
||||
});
|
||||
|
||||
test('Constructor22', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user