Since 0.9.1, indent : int, default=0 fails under the default config; it passed in 0.9.0. Turning on --check-arg-defaults=True to restore it also switches on default-checking for class attributes, where some attributes cannot be made to pass at all. The only way out disables class-attribute checking entirely.
There is no configuration that gives us both argument-default checking and class-attribute checking.
Reproduction
from dataclasses import dataclass, field
from enum import StrEnum
class Colour(StrEnum):
"""A colour.
Attributes
----------
RED
The colour red.
"""
RED = "RED"
@dataclass
class Config:
"""Rendering configuration.
Attributes
----------
indent : int
How far to indent.
tags : list[str]
Tags to emit.
"""
indent: int = 0
tags: list[str] = field(default_factory=list)
def render(colour: Colour, indent: int = 0) -> str:
"""Render a colour.
Parameters
----------
colour : Colour
The colour to render.
indent : int, default=0
How far to indent.
Returns
-------
str
The rendered colour.
"""
return " " * indent + colour
- Clean on 0.9.0.
$ uvx pydoclint@0.9.0 --style=numpy --quiet repro.py
$ echo $?
0
- On 0.9.1 the argument default is now rejected.
$ uvx pydoclint@0.9.1 --style=numpy --quiet repro.py
repro.py
33: DOC105: Function `render`: Argument names match, but type hints in these args do not match: indent
- Enabling
--check-arg-defaults fixes the function, but breaks both classes.
$ uvx pydoclint@0.9.1 --style=numpy --quiet --check-arg-defaults=True repro.py
repro.py
5: DOC605: Class `Colour`: Attribute names match, but type hints in these attributes do not match: RED
18: DOC605: Class `Config`: Attribute names match, but type hints in these attributes do not match: indent, tags
- The class docstrings cannot be fixed.
If we update to the following example:
from dataclasses import dataclass, field
from enum import StrEnum
class Colour(StrEnum):
"""A colour.
Attributes
----------
RED : , default='RED'
The colour red.
"""
RED = "RED"
@dataclass
class Config:
"""Rendering configuration.
Attributes
----------
indent : int, default=0
How far to indent.
tags : list[str], default=field(default_factory=list)
Tags to emit.
"""
indent: int = 0
tags: list[str] = field(default_factory=list)
def render(colour: Colour, indent: int = 0) -> str:
"""Render a colour.
Parameters
----------
colour : Colour
The colour to render.
indent : int, default=0
How far to indent.
Returns
-------
str
The rendered colour.
"""
return " " * indent + colour
Everything passes under uvx pydoclint@0.9.1 --style=numpy --quiet --check-arg-defaults=True repro_fixed.py but
Config will need to have tags : list[str], default=field(default_factory=list), not with the default value.
Colour.RED needs to be type-hinted as , default='RED'. RED, RED : str, and RED : str, default='RED' all fails.
- So the only passing configuration is to turn class attributes off.
$ uvx pydoclint@0.9.1 --style=numpy --quiet \
--check-arg-defaults=True --check-class-attributes=False repro.py
$ echo $?
0
That disables all DOC6xx checks, including attribute type-drift, which is the check we value most. Losing it to regain argument-default checking is a poor trade. How should I resovle this issue?
Since 0.9.1,
indent : int, default=0fails under the default config; it passed in 0.9.0. Turning on--check-arg-defaults=Trueto restore it also switches on default-checking for class attributes, where some attributes cannot be made to pass at all. The only way out disables class-attribute checking entirely.There is no configuration that gives us both argument-default checking and class-attribute checking.
Reproduction
--check-arg-defaultsfixes the function, but breaks both classes.If we update to the following example:
Everything passes under
uvx pydoclint@0.9.1 --style=numpy --quiet --check-arg-defaults=True repro_fixed.pybutConfigwill need to havetags : list[str], default=field(default_factory=list), not with the default value.Colour.REDneeds to be type-hinted as, default='RED'.RED,RED : str, andRED : str, default='RED'all fails.That disables all DOC6xx checks, including attribute type-drift, which is the check we value most. Losing it to regain argument-default checking is a poor trade. How should I resovle this issue?