@@ -1203,7 +1203,9 @@ def visit_func_def(self, defn: FuncDef) -> None:
12031203 # been typechecked, and decorated methods will be
12041204 # checked when the decorator is.
12051205 found_method_base_classes = self .pure_check_method_override (defn )
1206- self .pure_check_explicit_override_decorator (defn , found_method_base_classes )
1206+ self .pure_check_explicit_override_decorator (
1207+ defn , found_method_base_classes
1208+ )
12071209 self .pure_check_inplace_operator_method (defn )
12081210 if defn .original_def :
12091211 # Override previous definition.
@@ -1313,7 +1315,9 @@ def check_func_def(
13131315 # function. In the first case, set up another reference with the
13141316 # precise type.
13151317 if not self .can_skip_diagnostics :
1316- self .pure_check_func_item (item , typ , name , defn = defn , original_typ = original_typ )
1318+ self .pure_check_func_item (
1319+ item , typ , name , defn = defn , original_typ = original_typ
1320+ )
13171321
13181322 # Fix the type if decorated with `@types.coroutine` or `@asyncio.coroutine`.
13191323 if defn .is_awaitable_coroutine :
@@ -1495,9 +1499,8 @@ def check_func_def(
14951499
14961500 if show_error :
14971501 if self .options .warn_no_return :
1498- if (
1499- not self .current_node_deferred
1500- and not isinstance (return_type , (NoneType , AnyType ))
1502+ if not self .current_node_deferred and not isinstance (
1503+ return_type , (NoneType , AnyType )
15011504 ):
15021505 # Control flow fell off the end of a function that was
15031506 # declared to return a non-None type.
@@ -1533,21 +1536,25 @@ def check_func_def(
15331536
15341537 self .binder = old_binder
15351538
1536- def pure_check_func_item (self , item : FuncItem , typ : CallableType , name : str | None , * , defn : FuncItem , original_typ : CallableType ) -> None :
1539+ def pure_check_func_item (
1540+ self ,
1541+ item : FuncItem ,
1542+ typ : CallableType ,
1543+ name : str | None ,
1544+ * ,
1545+ defn : FuncItem ,
1546+ original_typ : CallableType ,
1547+ ) -> None :
15371548 if isinstance (item , FuncDef ):
15381549 fdef = item
15391550 # Check if __init__ has an invalid return type.
15401551 if (
15411552 fdef .info
15421553 and fdef .name in ("__init__" , "__init_subclass__" )
1543- and not isinstance (
1544- get_proper_type (typ .ret_type ), (NoneType , UninhabitedType )
1545- )
1554+ and not isinstance (get_proper_type (typ .ret_type ), (NoneType , UninhabitedType ))
15461555 and not self .dynamic_funcs [- 1 ]
15471556 ):
1548- self .fail (
1549- message_registry .MUST_HAVE_NONE_RETURN_TYPE .format (fdef .name ), item
1550- )
1557+ self .fail (message_registry .MUST_HAVE_NONE_RETURN_TYPE .format (fdef .name ), item )
15511558
15521559 # Check validity of __new__ signature
15531560 if fdef .info and fdef .name == "__new__" :
@@ -1582,13 +1589,9 @@ def pure_check_func_item(self, item: FuncItem, typ: CallableType, name: str | No
15821589 # Refuse contravariant return type variable
15831590 if isinstance (typ .ret_type , TypeVarType ):
15841591 if typ .ret_type .variance == CONTRAVARIANT :
1585- self .fail (
1586- message_registry .RETURN_TYPE_CANNOT_BE_CONTRAVARIANT , typ .ret_type
1587- )
1592+ self .fail (message_registry .RETURN_TYPE_CANNOT_BE_CONTRAVARIANT , typ .ret_type )
15881593 self .pure_check_unbound_return_typevar (typ )
1589- elif (
1590- isinstance (original_typ .ret_type , TypeVarType ) and original_typ .ret_type .values
1591- ):
1594+ elif isinstance (original_typ .ret_type , TypeVarType ) and original_typ .ret_type .values :
15921595 # Since type vars with values are expanded, the return type is changed
15931596 # to a raw value. This is a hack to get it back.
15941597 self .pure_check_unbound_return_typevar (original_typ )
@@ -1597,9 +1600,7 @@ def pure_check_func_item(self, item: FuncItem, typ: CallableType, name: str | No
15971600 if defn .is_generator :
15981601 if defn .is_async_generator :
15991602 if not self .is_async_generator_return_type (typ .ret_type ):
1600- self .fail (
1601- message_registry .INVALID_RETURN_TYPE_FOR_ASYNC_GENERATOR , typ
1602- )
1603+ self .fail (message_registry .INVALID_RETURN_TYPE_FOR_ASYNC_GENERATOR , typ )
16031604 else :
16041605 if not self .is_generator_return_type (typ .ret_type , defn .is_coroutine ):
16051606 self .fail (message_registry .INVALID_RETURN_TYPE_FOR_GENERATOR , typ )
@@ -3451,9 +3452,11 @@ def check_assignment(
34513452 rvalue_type = remove_instance_last_known_values (rvalue_type )
34523453 self .infer_variable_type (inferred , lvalue , rvalue_type , rvalue )
34533454 self .check_assignment_to_slots (lvalue )
3454- if isinstance (lvalue , RefExpr ) and not (
3455- isinstance (lvalue , NameExpr ) and lvalue .name == "__match_args__"
3456- ) and not self .can_skip_diagnostics :
3455+ if (
3456+ isinstance (lvalue , RefExpr )
3457+ and not (isinstance (lvalue , NameExpr ) and lvalue .name == "__match_args__" )
3458+ and not self .can_skip_diagnostics
3459+ ):
34573460 # We check override here at the end after storing the inferred type, since
34583461 # override check will try to access the current attribute via symbol tables
34593462 # (like a regular attribute access).
@@ -3570,11 +3573,15 @@ def pure_check_compatibility_all_supers(self, lvalue: RefExpr, rvalue: Expressio
35703573 for base in lvalue_node .info .mro [1 :]:
35713574 tnode = base .names .get (lvalue_node .name )
35723575 if tnode is not None :
3573- if not self .pure_check_compatibility_classvar_super (lvalue_node , base , tnode .node ):
3576+ if not self .pure_check_compatibility_classvar_super (
3577+ lvalue_node , base , tnode .node
3578+ ):
35743579 # Show only one error per variable
35753580 break
35763581
3577- if not self .pure_check_compatibility_final_super (lvalue_node , base , tnode .node ):
3582+ if not self .pure_check_compatibility_final_super (
3583+ lvalue_node , base , tnode .node
3584+ ):
35783585 # Show only one error per variable
35793586 break
35803587
0 commit comments