File tree 2 files changed +13
-2
lines changed 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -460,10 +460,13 @@ def infer_function_type_arguments_using_context(
460
460
# See also github issues #462 and #360.
461
461
ret_type = NoneTyp ()
462
462
args = infer_type_arguments (callable .type_var_ids (), ret_type , erased_ctx )
463
- # Only substitute non-None and non-erased types.
463
+ # Only substitute non-Uninhabited and non-erased types.
464
464
new_args = [] # type: List[Type]
465
465
for arg in args :
466
- if isinstance (arg , (NoneTyp , UninhabitedType )) or has_erased_component (arg ):
466
+ if isinstance (arg , UninhabitedType ) or has_erased_component (arg ):
467
+ new_args .append (None )
468
+ elif not experiments .STRICT_OPTIONAL and isinstance (arg , NoneTyp ):
469
+ # Don't substitute None types in non-strict-Optional mode.
467
470
new_args .append (None )
468
471
else :
469
472
new_args .append (arg )
Original file line number Diff line number Diff line change @@ -428,3 +428,11 @@ x + 1
428
428
[out]
429
429
main:2: note: In module imported here:
430
430
tmp/a.py:3: error: Unsupported left operand type for + (some union)
431
+
432
+ [case testNoneContextInference]
433
+ from typing import Dict, List
434
+ def f() -> List[None]:
435
+ return []
436
+ def g() -> Dict[None, None]:
437
+ return {}
438
+ [builtins fixtures/dict.pyi]
You can’t perform that action at this time.
0 commit comments