Skip to content

Commit 0edd113

Browse files
committed
Fix @no_type_check; handle decorated overloads
1 parent b8cff96 commit 0edd113

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

mypy/semanal_infer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def infer_decorator_signature_if_simple(
3131
"""
3232
if dec.var.is_property:
3333
# Decorators are expected to have a callable type (it's a little odd).
34+
# TODO: this may result in wrong type if @property is applied to decorated method.
3435
if dec.func.type is None:
3536
dec.var.type = CallableType(
3637
[AnyType(TypeOfAny.special_form)],
@@ -47,6 +48,8 @@ def infer_decorator_signature_if_simple(
4748
for expr in dec.decorators:
4849
preserve_type = False
4950
if isinstance(expr, RefExpr) and isinstance(expr.node, FuncDef):
51+
if expr.fullname == "typing.no_type_check":
52+
return
5053
if expr.node.type and is_identity_signature(expr.node.type):
5154
preserve_type = True
5255
if not preserve_type:

mypy/typeops.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ def type_object_type(info: TypeInfo, named_type: Callable[[str], Instance]) -> P
217217
# Construct callable type based on signature of __init__. Adjust
218218
# return type and insert type arguments.
219219
if isinstance(method, FuncBase):
220+
if isinstance(method, OverloadedFuncDef) and not method.type:
221+
allow_cache = False
220222
t = function_type(method, fallback)
221223
else:
222224
assert isinstance(method.type, ProperType)
@@ -886,8 +888,8 @@ def function_type(func: FuncBase, fallback: Instance) -> FunctionLike:
886888
if isinstance(func, FuncItem):
887889
return callable_type(func, fallback)
888890
else:
889-
# Broken overloads can have self.type set to None.
890-
# TODO: should we instead always set the type in semantic analyzer?
891+
# Either a broken overload, or decorated overload type is not ready.
892+
# TODO: make sure the caller defers if possible.
891893
assert isinstance(func, OverloadedFuncDef)
892894
any_type = AnyType(TypeOfAny.from_error)
893895
dummy = CallableType(

0 commit comments

Comments
 (0)