[issue41231] Type annotations lost when using wraps by default

David Caro report at bugs.python.org
Wed Jul 8 06:31:08 EDT 2020


David Caro <david at dcaro.es> added the comment:

Elaborating on the last message, given the following code:
```
  1 #!/usr/bin/env python3
  2 
  3 from functools import wraps
  4 
  5 
  6 def return_string(wrapped):
  7     @wraps(wrapped)
  8     def wrapper(an_int: int) -> str:
  9         return str(wrapped(an_int))
 10 
 11     return wrapper
 12 
 13 
 14 @return_string
 15 def identity(an_int: int) -> int:
 16     return an_int
 17 
 18 def print_bool(a_bool: bool) -> None:
 19     print(a_bool)
 20 
 21 def identity_nonwrapped(an_int: int) -> int:
 22     return an_int
 23 
 24 
 25 print_bool(a_bool=identity(7))
 26 print_bool(a_bool=identity_nonwrapped(7))
```

mypy will complain only on the last line, being unable to check properly the line 25.

I'll investigate a bit more on why mypy skips that.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41231>
_______________________________________


More information about the Python-bugs-list mailing list