agronholm / agronholm/typeguard
Title: @typechecked decorator does not preserve function signature, causing false "unexpected argument" errors in PyCharm
- Lingua principale
- Python
- Stelle
- 1.8k
- Fork
- 145
- Merge medio
- 8g 12h
- PR unite (30g)
- 1
Descrizione
### Things to check first
- [x] I have searched the existing issues and didn't find my bug already reported there
- [x] I have checked that my bug is still present in the latest release
### Typeguard version
4.x
### Python version
3.13
### What happened?
**Description:**
Since recent versions of PyCharm have improved their static type analysis, the @typechecked decorator from typeguard v3/v4 causes false "unexpected argument" errors for all parameters of decorated functions.
**Root Cause:**
In typeguard v2, @typechecked used functools.wraps internally, which preserved the original function's __wrapped__ metadata and signature. PyCharm (and other static analysis tools) could therefore look through the wrapper and inspect the original signature correctly.
In typeguard v3+, the decorator generates a wrapper that does not fully preserve the original signature in a way that PyCharm's type checker can resolve. As a result, PyCharm treats the wrapped function as having no defined parameters, and reports every argument passed to it as "unexpected".
**Expected behavior:**
@typechecked should preserve the original function signature so that static analysis tools can inspect it correctly — as was the case in typeguard v2.
**Suggested fix:**
Apply functools.update_wrapper (or functools.wraps) inside the decorator implementation to ensure __wrapped__, __annotations__, and __signature__ are correctly propagated to the wrapper function.
### How can we reproduce the bug?
use the current pycharm version with a project where typeguard is used.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.