Code Completion doesn't work for (class) functions decorated with decorators that return inner functions
So, decorated functions break down when when the decorator returns an inner function. This is not necessarily the case for stand-alone functions (unless they return other functions), but class functions show that effect immediately.
As can be seen, I get code completion for this class. But when I try to use code completion for return values, there's nothing:
Even though the viewer does have several functions, none are shown, as the returning type is "Any". If I explicitly name the type for the receiving variable, I have code completion:
So PyCharm does recognize the classes.
At the same time, none of the functions in that package give me parameter hints after I select a function:
As you can see (apart from the wrong documentation style) the function takes a file_name of type str, but the parameter hint only shows *args, **kwargs.
I don't have that problem in VS Code:
This does not happen in PyCharm 2020.2.5 nor in 2020.3
Please sign in to leave a comment.
Update: So PyCharm 2021+ works with decorators, as long as those decorators don't return generic inner functions:
The first decorator prevents parameter hinting (instead you just see P: ParamSpec("P")) and its return type is Any if used on a class function.
The second decorator does not prevent that. The try block is useless, but it's just to show why we need inner functions.
At least some feedback on this issue would be nice. I mean, this bug literally breaks THE key feature of an IDE..code completion.
Apparently code completion is not as important...
Wickermoon could you solve the problem?
One more thing, what are P and R in your first comment?
Still happening for decorators returning `wrapper(*args, **kwargs)`
Ran into something similar on IntelliJ `Build #IU-231.9011.4` with Python extension `231.9011.4` and the `@serde` decorator from `pyserde`. I get no autocomplete here:
If I remove the `@serde` decorator, autocomplete works normally. Here's the code for the `@serde` decorator at the time of writing:
Seems to be working fine for me:
What Python version do you use?
Sergey Karpov Hmm, interesting. I'm using Python 3.8.16. What about you?
I was looking in the wrong place, sorry. Reproduced https://youtrack.jetbrains.com/issue/PY-60559/No-completion-and-inspections-for-class-attributes-when-decorated-with-serde
There's already a ticket for that bug:
https://youtrack.jetbrains.com/issue/PY-53314/PyCharm-code-completion-not-working-for-annotated-class-functions