Skip to content

Commit 8861e28

Browse files
ilevkivskyigvanrossum
authored andcommitted
Process the decorator's Vars (#4375)
Fixes original crash in #4370
1 parent 080e345 commit 8861e28

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

mypy/semanal_pass3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def visit_decorator(self, dec: Decorator) -> None:
162162
name=dec.var.name())
163163
elif isinstance(dec.func.type, CallableType):
164164
dec.var.type = dec.func.type
165+
self.analyze(dec.var.type, dec.var)
165166
return
166167
decorator_preserves_type = True
167168
for expr in dec.decorators:
@@ -189,6 +190,7 @@ def visit_decorator(self, dec: Decorator) -> None:
189190
orig_sig = function_type(dec.func, self.builtin_type('function'))
190191
sig.name = orig_sig.items()[0].name
191192
dec.var.type = sig
193+
self.analyze(dec.var.type, dec.var)
192194

193195
def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
194196
"""Traverse the assignment statement.

test-data/unit/pythoneval-asyncio.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,21 @@ loop.run_until_complete(h())
484484
loop.close()
485485
[out]
486486
_program.py:16: error: Incompatible types in assignment (expression has type "A", variable has type "B")
487+
488+
[case testForwardRefToBadAsyncShouldNotCrash]
489+
from typing import TypeVar
490+
import asyncio
491+
492+
T = TypeVar('T')
493+
P = whatever # type: ignore
494+
495+
def test() -> None:
496+
reveal_type(bad)
497+
bad(0)
498+
499+
@asyncio.coroutine
500+
def bad(arg: P) -> T:
501+
pass
502+
[out]
503+
_program.py:8: error: Revealed type is 'def [T] (arg: P?) -> T`-1'
504+
_program.py:12: error: Invalid type "_testForwardRefToBadAsyncShouldNotCrash.P"

0 commit comments

Comments
 (0)