How write annotiations on python/pycharm for document ‘magic’ methods

Answered

In PHP, the @method tag allows the author to communicate the type of the arguments and return value of magic methods by including those types in the signature.

The @method tag is used in situation where a class contains the __call() magic method. This is really cool and heful for autocompletion while working with magic code. There is something like this for PyCharm/Python?

4 comments

Hi,

I didn't understand the question entirely (maybe because I'm not familiar with PHP that much), but I think the closest thing to what you're asking is type hinting in Python. It would be helpful if you provide a more concrete example of what you're trying to do and the result you wish to see. 

0

Thanks for replying. No worries.

On the example below, I would like that `bar_async` to appear on the autocompletion list.

0

Hi, one way to do it is to define Python stubs for Foo class, e.g. assuming it's a sample.py file, let's create a sample.pyi in the same folder with the following content

class Foo:
def bar(self) -> str: ...
def bar_async(self) -> str: ...

Now completion should work fine.

1

Please sign in to leave a comment.