File tree 2 files changed +18
-15
lines changed 2 files changed +18
-15
lines changed Original file line number Diff line number Diff line change @@ -2074,12 +2074,12 @@ def get_declared_metaclass(
2074
2074
# Probably a name error - it is already handled elsewhere
2075
2075
return None , False
2076
2076
if isinstance (sym .node , Var ) and isinstance (get_proper_type (sym .node .type ), AnyType ):
2077
- # 'Any' metaclass -- just ignore it.
2078
- #
2079
- # TODO: A better approach would be to record this information
2080
- # and assume that the type object supports arbitrary
2081
- # attributes, similar to an 'Any' base class.
2082
- return None , False
2077
+ # Create a fake TypeInfo that fallbacks to `Any`, basically allowing
2078
+ # all the attributes. Same thing as we do for `Any` base class.
2079
+ any_info = self . make_empty_type_info ( ClassDef ( sym . node . name , Block ([])))
2080
+ any_info . fallback_to_any = True
2081
+ any_info . _fullname = sym . node . fullname
2082
+ return Instance ( any_info , []) , False
2083
2083
if isinstance (sym .node , PlaceholderNode ):
2084
2084
return None , True # defer later in the caller
2085
2085
Original file line number Diff line number Diff line change @@ -4392,6 +4392,17 @@ 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
+
4395
4406
[case testMetaclassIterable]
4396
4407
from typing import Iterable, Iterator
4397
4408
@@ -4476,15 +4487,7 @@ from missing import M
4476
4487
class A(metaclass=M):
4477
4488
y = 0
4478
4489
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"
4490
+ reveal_type(A.x) # N: Revealed type is "Any"
4488
4491
4489
4492
[case testValidTypeAliasAsMetaclass]
4490
4493
from typing_extensions import TypeAlias
You can’t perform that action at this time.
0 commit comments