Search code examples
pythonpython-3.xpylinttype-hintingdocstring

PEP-526 Is not compatible with docstrings for class variables?


It appears if I use PEP-526 for class-level variables I must document them in the class's docstring in which case I need to pick my favorite way to do this.

Python 3.6.4 pylint==1.8.4

class Joe(object):
  counter: int = 0
  """This is a counter"""

pylint says (correctly, regardless of whether the variable is assigned to):

W: 3, 2: String statement has no effect (pointless-string-statement)


Solution

  • It's not PEP 526 being incompatible with the docstring; it's Pylint not understanding what you've done. Wait for an update.

    Some tools support a concept of docstrings for class variables, but it's never been part of Python itself, and PEP 526 doesn't change things.