@@ -89,29 +89,29 @@ def visit_Name(self, node):
89
89
90
90
def _check_not_in (self , name , names , curkind , newkind , loc ):
91
91
if name in names :
92
- diag = diagnostic .Diagnostic (' fatal' ,
92
+ diag = diagnostic .Diagnostic (" fatal" ,
93
93
"name '{name}' cannot be {curkind} and {newkind} simultaneously" ,
94
94
{"name" : name , "curkind" : curkind , "newkind" : newkind }, loc )
95
95
self .engine .process (diag )
96
96
97
97
def visit_Global (self , node ):
98
98
for name , loc in zip (node .names , node .name_locs ):
99
- self ._check_not_in (name , self .nonlocal_ , ' nonlocal' , ' global' , loc )
100
- self ._check_not_in (name , self .params , ' a parameter' , ' global' , loc )
99
+ self ._check_not_in (name , self .nonlocal_ , " nonlocal" , " global" , loc )
100
+ self ._check_not_in (name , self .params , " a parameter" , " global" , loc )
101
101
self .global_ .add (name )
102
102
103
103
def visit_Nonlocal (self , node ):
104
104
for name , loc in zip (node .names , node .name_locs ):
105
- self ._check_not_in (name , self .global_ , ' global' , ' nonlocal' , loc )
106
- self ._check_not_in (name , self .params , ' a parameter' , ' nonlocal' , loc )
105
+ self ._check_not_in (name , self .global_ , " global" , " nonlocal" , loc )
106
+ self ._check_not_in (name , self .params , " a parameter" , " nonlocal" , loc )
107
107
108
108
found = False
109
109
for outer_env in reversed (self .env_stack ):
110
110
if name in outer_env :
111
111
found = True
112
112
break
113
113
if not found :
114
- diag = diagnostic .Diagnostic (' fatal' ,
114
+ diag = diagnostic .Diagnostic (" fatal" ,
115
115
"can't declare name '{name}' as nonlocal: it is not bound in any outer scope" ,
116
116
{"name" : name },
117
117
loc , [node .keyword_loc ])
@@ -137,29 +137,29 @@ def _unify(self, typea, typeb, loca, locb, kind):
137
137
except types .UnificationError as e :
138
138
printer = types .TypePrinter ()
139
139
140
- if kind == ' generic' :
141
- note1 = diagnostic .Diagnostic (' note' ,
140
+ if kind == " generic" :
141
+ note1 = diagnostic .Diagnostic (" note" ,
142
142
"expression of type {typea}" ,
143
143
{"typea" : printer .name (typea )},
144
144
loca )
145
- elif kind == ' expects' :
146
- note1 = diagnostic .Diagnostic (' note' ,
145
+ elif kind == " expects" :
146
+ note1 = diagnostic .Diagnostic (" note" ,
147
147
"expression expecting an operand of type {typea}" ,
148
148
{"typea" : printer .name (typea )},
149
149
loca )
150
150
151
- note2 = diagnostic .Diagnostic (' note' ,
151
+ note2 = diagnostic .Diagnostic (" note" ,
152
152
"expression of type {typeb}" ,
153
153
{"typeb" : printer .name (typeb )},
154
154
locb )
155
155
156
156
if e .typea .find () == typea .find () and e .typeb .find () == typeb .find ():
157
- diag = diagnostic .Diagnostic (' fatal' ,
157
+ diag = diagnostic .Diagnostic (" fatal" ,
158
158
"cannot unify {typea} with {typeb}" ,
159
159
{"typea" : printer .name (typea ), "typeb" : printer .name (typeb )},
160
160
loca , [locb ], notes = [note1 , note2 ])
161
161
else : # give more detail
162
- diag = diagnostic .Diagnostic (' fatal' ,
162
+ diag = diagnostic .Diagnostic (" fatal" ,
163
163
"cannot unify {typea} with {typeb}: {fraga} is incompatible with {fragb}" ,
164
164
{"typea" : printer .name (typea ), "typeb" : printer .name (typeb ),
165
165
"fraga" : printer .name (e .typea ), "fragb" : printer .name (e .typeb )},
@@ -187,7 +187,7 @@ def _find_name(self, name, loc):
187
187
for typing_env in reversed (self .env_stack ):
188
188
if name in typing_env :
189
189
return typing_env [name ]
190
- diag = diagnostic .Diagnostic (' fatal' ,
190
+ diag = diagnostic .Diagnostic (" fatal" ,
191
191
"name '{name}' is not bound to anything" , {"name" :name }, loc )
192
192
self .engine .process (diag )
193
193
@@ -204,7 +204,7 @@ def visit_Num(self, node):
204
204
elif isinstance (node .n , float ):
205
205
typ = types .TFloat ()
206
206
else :
207
- diag = diagnostic .Diagnostic (' fatal' ,
207
+ diag = diagnostic .Diagnostic (" fatal" ,
208
208
"numeric type {type} is not supported" , {"type" : node .n .__class__ .__name__ },
209
209
node .loc )
210
210
self .engine .process (diag )
@@ -225,8 +225,8 @@ def visit_List(self, node):
225
225
node = asttyped .ListT (type = types .TList (),
226
226
elts = node .elts , ctx = node .ctx , loc = node .loc )
227
227
for elt in node .elts :
228
- self ._unify (node .type [' elt' ], elt .type ,
229
- node .loc , elt .loc , kind = ' expects' )
228
+ self ._unify (node .type [" elt" ], elt .type ,
229
+ node .loc , elt .loc , kind = " expects" )
230
230
return node
231
231
232
232
def visit_Subscript (self , node ):
@@ -236,7 +236,7 @@ def visit_Subscript(self, node):
236
236
loc = node .loc )
237
237
# TODO: support more than just lists
238
238
self ._unify (types .TList (node .type ), node .value .type ,
239
- node .loc , node .value .loc , kind = ' expects' )
239
+ node .loc , node .value .loc , kind = " expects" )
240
240
return node
241
241
242
242
# Visitors that just unify types
@@ -267,7 +267,7 @@ def visit_For(self, node):
267
267
# Unsupported visitors
268
268
#
269
269
def visit_unsupported (self , node ):
270
- diag = diagnostic .Diagnostic (' fatal' ,
270
+ diag = diagnostic .Diagnostic (" fatal" ,
271
271
"this syntax is not supported" , {},
272
272
node .loc )
273
273
self .engine .process (diag )
@@ -301,7 +301,7 @@ def rewrite(self):
301
301
return self .rewriter .rewrite ()
302
302
303
303
def generic_visit (self , node ):
304
- if hasattr (node , ' type' ):
304
+ if hasattr (node , " type" ):
305
305
self .rewriter .insert_after (node .loc ,
306
306
":%s" .format (self .type_printer .name (node .type )))
307
307
0 commit comments