Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm **kwargs auto-complete

Hi I'm trying to make pycharm's auto-complete works with **kwargs. To do this I'm wrote a doc string using epytext syntax which has a way to declare keyword arguments with @keyword p: but it doesn't works.

Example

Do someone know the way to fix it?

P.S. I have changed a docstring format in PyCharm setting.

like image 350
Taras Protsenko Avatar asked May 31 '26 09:05

Taras Protsenko


1 Answers

If the keyword arguments are known ahead of time (and you want a docstring to explain them), then they should be explicitly listed in the function parameters. Each one can then be described with the normal @param & @type syntax. @keywords is used to describe the rest of the keyword arguments that are unknown at development time.

For example:

class SomeClass:
  def __init__(self, some_kw=None, some_kw_1=None, **other_kwargs):
    """
    @param some_kw: A known-at-dev-time keyword argument
    @type some_kw: str
    @param some_kw_1: Another known-at-dev-time keyword argument
    @type some_kw_1: str
    @keyword other_kwargs: More kwargs that will be set on the instance
    """
    self.some_kw = some_kw
    self.some_kw_1 = some_kw_1
    for k, v in other_kwargs:
        setattr(self, k, v)

an_instance = SomeClass(some_kw="hello", other_kw="world")
print an_instance.some_kw
print an_instance.some_kw_1
print an_instance.other_kw

Output

> "hello"
> None
> "world"
like image 79
ntrrobng Avatar answered Jun 03 '26 00:06

ntrrobng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!