2323Param = overlay_utils .Param
2424
2525
26+ def _is_typing_container (cls : pytd .Class ):
27+ return pytd .IsContainer (cls ) and cls .template
28+
29+
2630class TypingOverlay (overlay .Overlay ):
2731 """A representation of the 'typing' module that allows custom overlays.
2832
@@ -39,7 +43,7 @@ def __init__(self, ctx):
3943 ast = ctx .loader .typing
4044 for cls in ast .classes :
4145 _ , 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 ):
4347 member_map [name ] = (overlay .build (name , TypingContainer ), None )
4448 super ().__init__ (ctx , "typing" , member_map , ast )
4549
@@ -70,7 +74,7 @@ def __init__(self, module_name, aliases, ctx):
7074 for pyval in ast .aliases + ast .classes + ast .constants + ast .functions :
7175 # Any public members that are not explicitly implemented are unsupported.
7276 _ , name = pyval .name .rsplit ("." , 1 )
73- if name .startswith ("_" ):
77+ if name .startswith ("_" ) or name in member_map :
7478 continue
7579 if name in typing_overlay :
7680 member_map [name ] = typing_overlay [name ][0 ]
@@ -84,6 +88,9 @@ def __init__(self, module_name, aliases, ctx):
8488def _build (name ):
8589 def resolve (ctx ):
8690 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 )
8794 pytd_type = pytd .ToType (ast .Lookup (name ), True , True , True )
8895 return ctx .convert .constant_to_value (pytd_type )
8996 return resolve
0 commit comments