10

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.

4

1 Answer 1

0

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"
1
  • 3
    The point is to not have them there but have PyCharm suggest them to you. Aug 12, 2019 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.