@@ -4392,6 +4392,35 @@ def f(TB: Type[B]):
4392
4392
reveal_type(TB) # N: Revealed type is "Type[__main__.B]"
4393
4393
reveal_type(TB.x) # N: Revealed type is "builtins.int"
4394
4394
4395
+ [case testMetaclassAsAny]
4396
+ from typing import Any, ClassVar
4397
+
4398
+ MyAny: Any
4399
+ class WithMeta(metaclass=MyAny):
4400
+ x: ClassVar[int]
4401
+
4402
+ reveal_type(WithMeta.a) # N: Revealed type is "Any"
4403
+ reveal_type(WithMeta.m) # N: Revealed type is "Any"
4404
+ reveal_type(WithMeta.x) # N: Revealed type is "builtins.int"
4405
+ reveal_type(WithMeta().x) # N: Revealed type is "builtins.int"
4406
+ WithMeta().m # E: "WithMeta" has no attribute "m"
4407
+ WithMeta().a # E: "WithMeta" has no attribute "a"
4408
+
4409
+ [case testMetaclassAsAnyWithAFlag]
4410
+ # flags: --disallow-subclassing-any
4411
+ from typing import Any, ClassVar
4412
+
4413
+ MyAny: Any
4414
+ class WithMeta(metaclass=MyAny): # E: Class cannot use "__main__.MyAny" as a metaclass (has type "Any")
4415
+ x: ClassVar[int]
4416
+
4417
+ reveal_type(WithMeta.a) # N: Revealed type is "Any"
4418
+ reveal_type(WithMeta.m) # N: Revealed type is "Any"
4419
+ reveal_type(WithMeta.x) # N: Revealed type is "builtins.int"
4420
+ reveal_type(WithMeta().x) # N: Revealed type is "builtins.int"
4421
+ WithMeta().m # E: "WithMeta" has no attribute "m"
4422
+ WithMeta().a # E: "WithMeta" has no attribute "a"
4423
+
4395
4424
[case testMetaclassIterable]
4396
4425
from typing import Iterable, Iterator
4397
4426
@@ -4476,15 +4505,7 @@ from missing import M
4476
4505
class A(metaclass=M):
4477
4506
y = 0
4478
4507
reveal_type(A.y) # N: Revealed type is "builtins.int"
4479
- A.x # E: "Type[A]" has no attribute "x"
4480
-
4481
- [case testAnyMetaclass]
4482
- from typing import Any
4483
- M = None # type: Any
4484
- class A(metaclass=M):
4485
- y = 0
4486
- reveal_type(A.y) # N: Revealed type is "builtins.int"
4487
- A.x # E: "Type[A]" has no attribute "x"
4508
+ reveal_type(A.x) # N: Revealed type is "Any"
4488
4509
4489
4510
[case testValidTypeAliasAsMetaclass]
4490
4511
from typing_extensions import TypeAlias
0 commit comments