23
23
Param = overlay_utils .Param
24
24
25
25
26
+ def _is_typing_container (cls : pytd .Class ):
27
+ return pytd .IsContainer (cls ) and cls .template
28
+
29
+
26
30
class TypingOverlay (overlay .Overlay ):
27
31
"""A representation of the 'typing' module that allows custom overlays.
28
32
@@ -39,7 +43,7 @@ def __init__(self, ctx):
39
43
ast = ctx .loader .typing
40
44
for cls in ast .classes :
41
45
_ , name = cls .name .rsplit ("." , 1 )
42
- if name not in member_map and pytd . IsContainer (cls ) and cls . template :
46
+ if name not in member_map and _is_typing_container (cls ):
43
47
member_map [name ] = (overlay .build (name , TypingContainer ), None )
44
48
super ().__init__ (ctx , "typing" , member_map , ast )
45
49
@@ -70,7 +74,7 @@ def __init__(self, module_name, aliases, ctx):
70
74
for pyval in ast .aliases + ast .classes + ast .constants + ast .functions :
71
75
# Any public members that are not explicitly implemented are unsupported.
72
76
_ , name = pyval .name .rsplit ("." , 1 )
73
- if name .startswith ("_" ):
77
+ if name .startswith ("_" ) or name in member_map :
74
78
continue
75
79
if name in typing_overlay :
76
80
member_map [name ] = typing_overlay [name ][0 ]
@@ -84,6 +88,9 @@ def __init__(self, module_name, aliases, ctx):
84
88
def _build (name ):
85
89
def resolve (ctx ):
86
90
ast = ctx .loader .typing
91
+ pytd_val = ast .Lookup (name )
92
+ if isinstance (pytd_val , pytd .Class ) and _is_typing_container (pytd_val ):
93
+ return TypingContainer (name .rsplit ("." , 1 )[- 1 ], ctx )
87
94
pytd_type = pytd .ToType (ast .Lookup (name ), True , True , True )
88
95
return ctx .convert .constant_to_value (pytd_type )
89
96
return resolve
0 commit comments