@@ -1262,13 +1262,27 @@ def check_default_args(self, item: FuncItem, body_is_trivial: bool) -> None:
1262
1262
msg += f"tuple argument { name [12 :]} "
1263
1263
else :
1264
1264
msg += f'argument "{ name } "'
1265
+ if (
1266
+ not self .options .implicit_optional
1267
+ and isinstance (arg .initializer , NameExpr )
1268
+ and arg .initializer .fullname == "builtins.None"
1269
+ ):
1270
+ notes = [
1271
+ "PEP 484 prohibits implicit Optional. "
1272
+ "Accordingly, mypy has changed its default to no_implicit_optional=True" ,
1273
+ "Use https://github.com/hauntsaninja/no_implicit_optional to automatically "
1274
+ "upgrade your codebase" ,
1275
+ ]
1276
+ else :
1277
+ notes = None
1265
1278
self .check_simple_assignment (
1266
1279
arg .variable .type ,
1267
1280
arg .initializer ,
1268
1281
context = arg .initializer ,
1269
1282
msg = ErrorMessage (msg , code = codes .ASSIGNMENT ),
1270
1283
lvalue_name = "argument" ,
1271
1284
rvalue_name = "default" ,
1285
+ notes = notes ,
1272
1286
)
1273
1287
1274
1288
def is_forward_op_method (self , method_name : str ) -> bool :
@@ -3739,6 +3753,8 @@ def check_simple_assignment(
3739
3753
msg : ErrorMessage = message_registry .INCOMPATIBLE_TYPES_IN_ASSIGNMENT ,
3740
3754
lvalue_name : str = "variable" ,
3741
3755
rvalue_name : str = "expression" ,
3756
+ * ,
3757
+ notes : list [str ] | None = None ,
3742
3758
) -> Type :
3743
3759
if self .is_stub and isinstance (rvalue , EllipsisExpr ):
3744
3760
# '...' is always a valid initializer in a stub.
@@ -3763,6 +3779,7 @@ def check_simple_assignment(
3763
3779
msg ,
3764
3780
f"{ rvalue_name } has type" ,
3765
3781
f"{ lvalue_name } has type" ,
3782
+ notes = notes ,
3766
3783
)
3767
3784
return rvalue_type
3768
3785
@@ -5666,6 +5683,7 @@ def check_subtype(
5666
5683
subtype_label : str | None = None ,
5667
5684
supertype_label : str | None = None ,
5668
5685
* ,
5686
+ notes : list [str ] | None = None ,
5669
5687
code : ErrorCode | None = None ,
5670
5688
outer_context : Context | None = None ,
5671
5689
) -> bool :
@@ -5681,6 +5699,7 @@ def check_subtype(
5681
5699
subtype_label : str | None = None ,
5682
5700
supertype_label : str | None = None ,
5683
5701
* ,
5702
+ notes : list [str ] | None = None ,
5684
5703
outer_context : Context | None = None ,
5685
5704
) -> bool :
5686
5705
...
@@ -5694,6 +5713,7 @@ def check_subtype(
5694
5713
subtype_label : str | None = None ,
5695
5714
supertype_label : str | None = None ,
5696
5715
* ,
5716
+ notes : list [str ] | None = None ,
5697
5717
code : ErrorCode | None = None ,
5698
5718
outer_context : Context | None = None ,
5699
5719
) -> bool :
@@ -5714,7 +5734,7 @@ def check_subtype(
5714
5734
return False
5715
5735
extra_info : list [str ] = []
5716
5736
note_msg = ""
5717
- notes : list [ str ] = []
5737
+ notes = notes or []
5718
5738
if subtype_label is not None or supertype_label is not None :
5719
5739
subtype_str , supertype_str = format_type_distinctly (orig_subtype , orig_supertype )
5720
5740
if subtype_label is not None :
@@ -5725,7 +5745,7 @@ def check_subtype(
5725
5745
outer_context or context , subtype , supertype , supertype_str
5726
5746
)
5727
5747
if isinstance (subtype , Instance ) and isinstance (supertype , Instance ):
5728
- notes = append_invariance_notes ([] , subtype , supertype )
5748
+ notes = append_invariance_notes (notes , subtype , supertype )
5729
5749
if extra_info :
5730
5750
msg = msg .with_additional_msg (" (" + ", " .join (extra_info ) + ")" )
5731
5751
0 commit comments