Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions mypy/applytype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/check-inference.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
-- -------------------------
Expand Down