@@ -239,13 +239,13 @@ class A:
239239# flags: --warn-uninitialized-attributes
240240class A:
241241 x: int
242- a = A() # E: Cannot instantiate abstract class "A" with abstract attribute "x"
242+ a = A() # E: Class "A" has annotated but unset attributes: "x"
243243class B(A):
244244 def __init__(self) -> None:
245245 self.x = 10
246246B() # OK
247247class C(A): ...
248- C() # E: Cannot instantiate abstract class "C" with abstract attribute "x"
248+ C() # E: Class "C" has annotated but unset attributes: "x"
249249class D(A):
250250 def f(self) -> None:
251251 self.x = "foo" # E: Incompatible types in assignment (expression has type "str", base class "A" defined the type as "int")
@@ -273,9 +273,9 @@ from abc import ABC
273273
274274class A(ABC):
275275 x: str
276- A() # E: Cannot instantiate abstract class "A" with abstract attribute "x"
276+ A() # E: Class "A" has annotated but unset attributes: "x"
277277class B(A): ...
278- B() # E: Cannot instantiate abstract class "B" with abstract attribute "x"
278+ B() # E: Class "B" has annotated but unset attributes: "x"
279279class C(A):
280280 def f(self) -> None:
281281 self.x = "foo"
@@ -287,11 +287,11 @@ class A:
287287 x: int
288288 y: str = "foo"
289289 z: bool
290- A() # E: Cannot instantiate abstract class "A" with abstract attributes "x" and "z"
290+ A() # E: Class "A" has annotated but unset attributes: "x" and "z"
291291class B(A):
292292 def __init__(self) -> None:
293293 self.x = 3
294- B() # E: Cannot instantiate abstract class "B" with abstract attribute "z"
294+ B() # E: Class "B" has annotated but unset attributes: "z"
295295class C(B):
296296 def __init__(self) -> None:
297297 self.z = True
@@ -310,7 +310,7 @@ class A:
310310 @classmethod
311311 def f(cls) -> None:
312312 cls.z = True
313- A(3, "foo") # E: Cannot instantiate abstract class "A" with abstract attribute "z"
313+ A(3, "foo") # E: Class "A" has annotated but unset attributes: "z"
314314reveal_type(A.z) # N: Revealed type is "builtins.bool"
315315@dataclass
316316class A2(A):
@@ -323,7 +323,7 @@ class B:
323323
324324@dataclass
325325class C(B): ...
326- C() # E: Cannot instantiate abstract class "C" with abstract attributes "x" and "y"
326+ C() # E: Class "C" has annotated but unset attributes: "x" and "y"
327327
328328@dataclass
329329class D(B):
@@ -341,15 +341,15 @@ from typing import ClassVar
341341class A:
342342 x: int
343343 z: ClassVar[bool]
344- A(3) # E: Cannot instantiate abstract class "A" with abstract attribute "z"
344+ A(3) # E: Class "A" has annotated but unset attributes: "z"
345345
346346class B:
347347 x: int
348348 y: str
349349
350350@attr.define
351351class C(B): ...
352- C() # E: Cannot instantiate abstract class "C" with abstract attributes "x" and "y"
352+ C() # E: Class "C" has annotated but unset attributes: "x" and "y"
353353
354354@attr.define
355355class D(B):
@@ -400,14 +400,15 @@ if TYPE_CHECKING:
400400 class C(B): ...
401401else:
402402 class C: ...
403- C() # E: Cannot instantiate abstract class "C" with abstract attribute "x"
403+ C() # E: Class "C" has annotated but unset attributes: "x"
404404[file stub.pyi]
405405class A:
406406 x: int
407407
408408[case testUninitializedAttributeClassVar]
409409# flags: --warn-uninitialized-attributes
410410from typing import ClassVar
411+ from typing_extensions import Protocol
411412class A:
412413 CONST: int
413414 CONST = 4
@@ -417,3 +418,46 @@ class B:
417418 CONST: ClassVar[int]
418419 CONST = 4
419420B()
421+
422+ class C(Protocol):
423+ CONST: ClassVar[int]
424+ CONST = 4
425+ class D(C): ...
426+ D()
427+ [builtins fixtures/tuple.pyi]
428+
429+ [case testUninitializedAttributeSuperClass]
430+ # flags: --warn-uninitialized-attributes
431+ class A:
432+ def __init__(self, x: int):
433+ self.x = x
434+
435+ class B(A):
436+ x: int
437+ def __init__(self, x: int):
438+ super().__init__(x)
439+
440+ b = B(0)
441+ reveal_type(b.x) # N: Revealed type is "builtins.int"
442+
443+ class C:
444+ x: int
445+ class D(C):
446+ x: int
447+ D() # E: Class "D" has annotated but unset attributes: "x"
448+
449+ class E:
450+ a: int
451+ def __init__(self, a: int) -> None:
452+ self.a = a
453+
454+ class F(E):
455+ a: int
456+ b: int
457+ def __init__(self, a: int, b: int) -> None:
458+ super().__init__(a)
459+ # or `self.a = a`
460+ self.b = b
461+
462+ E(0) # ok
463+ F(1, 1) # ok
0 commit comments