@@ -284,6 +284,27 @@ def visit_BoolOp(self, node):
284
284
op_locs = node .op_locs , loc = node .loc )
285
285
return self .visit (node )
286
286
287
+ def visit_UnaryOp (self , node ):
288
+ node = self .generic_visit (node )
289
+ node = asttyped .UnaryOpT (type = types .TVar (),
290
+ op = node .op , operand = node .operand ,
291
+ loc = node .loc )
292
+ return self .visit (node )
293
+
294
+ def visit_BinOp (self , node ):
295
+ node = self .generic_visit (node )
296
+ node = asttyped .BinOpT (type = types .TVar (),
297
+ left = node .left , op = node .op , right = node .right ,
298
+ loc = node .loc )
299
+ return self .visit (node )
300
+
301
+ def visit_Compare (self , node ):
302
+ node = self .generic_visit (node )
303
+ node = asttyped .CompareT (type = types .TVar (),
304
+ left = node .left , ops = node .ops , comparators = node .comparators ,
305
+ loc = node .loc )
306
+ return self .visit (node )
307
+
287
308
# Visitors that just unify types
288
309
#
289
310
def visit_ListT (self , node ):
@@ -310,6 +331,21 @@ def visit_BoolOpT(self, node):
310
331
node .loc , value .loc , self ._makenotes_elts (node .values , "an operand" ))
311
332
return node
312
333
334
+ def visit_UnaryOpT (self , node ):
335
+ if isinstance (node .op , ast .Not ):
336
+ node .type = types .TBool ()
337
+ else :
338
+ operand_type = node .operand .type .find ()
339
+ if types .is_numeric (operand_type ):
340
+ node .type = operand_type
341
+ elif not types .is_var (operand_type ):
342
+ diag = diagnostic .Diagnostic ("error" ,
343
+ "expected operand to be of numeric type, not {type}" ,
344
+ {"type" : types .TypePrinter ().name (operand_type )},
345
+ node .operand .loc )
346
+ self .engine .process (diag )
347
+ return node
348
+
313
349
def visit_Assign (self , node ):
314
350
node = self .generic_visit (node )
315
351
if len (node .targets ) > 1 :
@@ -375,7 +411,6 @@ def visit_unsupported(self, node):
375
411
visit_SetComp = visit_unsupported
376
412
visit_Str = visit_unsupported
377
413
visit_Starred = visit_unsupported
378
- visit_UnaryOp = visit_unsupported
379
414
visit_Yield = visit_unsupported
380
415
visit_YieldFrom = visit_unsupported
381
416
0 commit comments