@@ -70,6 +70,7 @@ def __init__(self,
70
70
def visit_unbound_type (self , t : UnboundType ) -> Type :
71
71
sym = self .lookup (t .name , t )
72
72
if sym is not None :
73
+ fullname = sym .node .fullname ()
73
74
if sym .kind == TVAR :
74
75
if len (t .args ) > 0 :
75
76
self .fail ('Type variable "{}" used with arguments' .format (
@@ -81,18 +82,24 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
81
82
values = cast (TypeVarExpr , sym .node ).values
82
83
return TypeVar (t .name , sym .tvar_id , values , self .builtin_type ('builtins.object' ),
83
84
t .line , rep )
84
- elif sym . node . fullname () == 'builtins.None' :
85
+ elif fullname == 'builtins.None' :
85
86
return Void ()
86
- elif sym . node . fullname () == 'typing.Any' :
87
+ elif fullname == 'typing.Any' :
87
88
return AnyType ()
88
- elif sym . node . fullname () == 'typing.Tuple' :
89
+ elif fullname == 'typing.Tuple' :
89
90
return TupleType (self .anal_array (t .args ),
90
91
self .builtin_type ('builtins.tuple' ))
91
- elif sym . node . fullname () == 'typing.Union' :
92
+ elif fullname == 'typing.Union' :
92
93
items = self .anal_array (t .args )
93
94
items = [item for item in items if not isinstance (item , Void )]
94
95
return UnionType .make_union (items )
95
- elif sym .node .fullname () == 'typing.Callable' :
96
+ elif fullname == 'typing.Optional' :
97
+ if len (t .args ) != 1 :
98
+ self .fail ('Optional[...] must have exactly one type argument' , t )
99
+ items = self .anal_array (t .args )
100
+ # Currently Optional[t] is just an alias for t.
101
+ return items [0 ]
102
+ elif fullname == 'typing.Callable' :
96
103
return self .analyze_function_type (t )
97
104
elif sym .kind == TYPE_ALIAS :
98
105
# TODO: Generic type aliases.
@@ -109,7 +116,6 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
109
116
Instance (info , [], t .line ),
110
117
t .line , t .repr )
111
118
else :
112
-
113
119
# Analyze arguments and construct Instance type. The
114
120
# number of type arguments and their values are
115
121
# checked only later, since we do not always know the
0 commit comments