diff --git a/mypy/applytype.py b/mypy/applytype.py index d97670034a0bc..997d7ffd3d4dc 100644 --- a/mypy/applytype.py +++ b/mypy/applytype.py @@ -3,7 +3,7 @@ import mypy.subtypes from mypy.sametypes import is_same_type from mypy.expandtype import expand_type -from mypy.types import Type, TypeVarId, TypeVarType, CallableType, AnyType +from mypy.types import Type, TypeVarId, TypeVarType, CallableType, AnyType, PartialType from mypy.messages import MessageBuilder from mypy.nodes import Context @@ -34,14 +34,15 @@ def apply_generic_arguments(callable: CallableType, types: List[Type], for v1 in type.values): continue for value in values: - if mypy.subtypes.is_subtype(type, value): + if isinstance(type, PartialType) or mypy.subtypes.is_subtype(type, value): types[i] = value break else: msg.incompatible_typevar_value(callable, i + 1, type, context) upper_bound = callable.variables[i].upper_bound - if type and not mypy.subtypes.satisfies_upper_bound(type, upper_bound): + if (type and not isinstance(type, PartialType) and + not mypy.subtypes.satisfies_upper_bound(type, upper_bound)): msg.incompatible_typevar_value(callable, i + 1, type, context) # Create a map from type variable id to target type. diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index 799fb3525d703..e6b043923a671 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -935,6 +935,15 @@ if A: class A: pass class B: pass +[case testAssigningAnyStrToNone] +from typing import Tuple, TypeVar +AnyStr = TypeVar('AnyStr', str, bytes) + +def f(x: AnyStr) -> Tuple[AnyStr]: pass +x = None +(x,) = f('') +reveal_type(x) # E: Revealed type is 'builtins.str' + -- Inferring attribute types -- -------------------------