Skip to content

Commit 5b850f1

Browse files
committed
Add check-arg-defaults
1 parent b4776d9 commit 5b850f1

File tree

19 files changed

+803
-66
lines changed

19 files changed

+803
-66
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# Change Log
22

3-
## [Unpublished]
3+
## [0.7.0] - 2025-09-01
44

5+
- Added
6+
- A new config option `--check-arg-default` (default: False) to check
7+
consistency of argument defaults (between docstring and function signature)
58
- Changed
69
- Replace `Prettier` with: [yamlfix](https://github.com/lyz-code/yamlfix),
710
[mdformat](https://github.com/hukkin/mdformat), and
811
[pretty-format-json](https://github.com/pre-commit/pre-commit-hooks?tab=readme-ov-file#pretty-format-json)
12+
- Full diff
13+
- https://github.com/jsh9/pydoclint/compare/0.6.11...0.7.0
914

1015
## [0.6.11] - 2025-08-31
1116

CLAUDE.md

Lines changed: 97 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,108 @@
1-
# pydoclint Project Conventions
1+
# CLAUDE.md
22

3-
## Code Style
3+
This file provides guidance to Claude Code (claude.ai/code) when working with
4+
code in this repository.
5+
6+
## pydoclint Project Conventions
7+
8+
### Code Style
49

510
- Use camelCase for function and variable names (not snake_case)
611

7-
## Branch Naming
12+
### Branch Naming
813

914
- Format: `yyyy-mm-dd-What-this-branch-does`
1015

11-
## Commit Messages & PR Titles
16+
### Commit Messages & PR Titles
1217

1318
- Use action verbs (imperative mood), not past tense
1419
- Good: "Add feature", "Fix bug"
1520
- Bad: "Added feature", "Fixed bug"
21+
22+
## Development Commands
23+
24+
### Testing
25+
26+
- `pytest --tb=long .` - Run all tests with detailed traceback
27+
- `tox` - Run full test suite across multiple Python versions
28+
- `tox -e py311` - Run tests on specific Python version (py39, py310, py311,
29+
py312, py313)
30+
31+
### Code Quality
32+
33+
- `mypy pydoclint/` - Type checking
34+
- `muff format --diff --config=muff.toml pydoclint tests` - Format checking
35+
(use `--diff` to avoid accidental formatting)
36+
- `flake8 .` - Basic linting
37+
- `pydoclint --config=pyproject.toml .` - Self-check using pydoclint
38+
- `pre-commit run -a` - Run all pre-commit hooks
39+
40+
### Specialized Tox Commands
41+
42+
- `tox -e mypy` - Type checking only
43+
- `tox -e muff` - Format checking only
44+
- `tox -e check-self` - Run pydoclint on itself
45+
- `tox -e flake8-basic` - Basic flake8 checks
46+
- `tox -e flake8-misc` - Additional flake8 plugins
47+
- `tox -e flake8-docstrings` - Docstring style checks
48+
- `tox -e pre-commit` - Pre-commit hooks (skips muff formatter)
49+
50+
### Running a Single Test
51+
52+
Use pytest with specific test file or test function:
53+
54+
```bash
55+
pytest tests/test_main.py
56+
pytest tests/test_main.py::test_function_name
57+
```
58+
59+
## Architecture Overview
60+
61+
Pydoclint is a Python docstring linter that checks docstring sections against
62+
function signatures. The core architecture consists of:
63+
64+
### Main Components
65+
66+
- **main.py**: CLI entry point using Click, handles command-line options and
67+
orchestrates linting
68+
- **visitor.py**: AST visitor that traverses Python code and applies docstring
69+
checks
70+
- **flake8_entry.py**: Plugin interface for flake8 integration
71+
- **parse_config.py**: Configuration parsing from pyproject.toml and other
72+
sources
73+
- **baseline.py**: Baseline functionality for gradual adoption
74+
75+
### Utils Package Structure
76+
77+
- **arg.py/argList.py**: Function argument representation and handling
78+
- **doc.py**: Docstring parsing and representation
79+
- **return_arg.py/yield_arg.py**: Return/yield argument handling
80+
- **violation.py**: Violation representation and reporting
81+
- **astTypes.py**: AST type definitions and utilities
82+
- **generic.py**: Common utility functions
83+
- **method_type.py**: Method type detection (regular, static, class, property)
84+
- **parse_docstring.py**: Core docstring parsing for numpy/google/sphinx styles
85+
- **return_yield_raise.py**: Analysis of return/yield/raise statements in
86+
function bodies
87+
- **visitor_helper.py**: Helper functions for the main visitor
88+
89+
### Supported Docstring Styles
90+
91+
- **Numpy**: numpydoc format
92+
- **Google**: Google-style docstrings
93+
- **Sphinx**: Sphinx/reStructuredText format
94+
95+
### Key Features
96+
97+
- Fast AST-based analysis (thousands of times faster than darglint)
98+
- Supports type hint checking against docstring parameter types
99+
- Class attribute documentation checking
100+
- Baseline mode for gradual adoption in existing codebases
101+
- Both standalone CLI and flake8 plugin modes
102+
103+
### Test Structure
104+
105+
- `tests/data/` contains test cases organized by docstring style (google,
106+
numpy, sphinx, edge_cases)
107+
- Tests use real Python files with expected violations rather than string-based
108+
tests

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ Currently, _pydoclint_ supports three docstring styles:
2626
[numpy](https://numpydoc.readthedocs.io/en/latest/format.html),
2727
[Google](https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html),
2828
and
29-
[Sphinx](https://sphinx-rtd-tutorial.readthedocs.io/en/latest/docstrings.html).
29+
[Sphinx](https://sphinx-rtd-tutorial.readthedocs.io/en/latest/docstrings.html),
30+
with some
31+
[minor style deviations](https://jsh9.github.io/pydoclint/style_deviations.html).
3032

3133
Another note: this linter and [pydocstyle](https://github.com/PyCQA/pydocstyle)
3234
serves complementary purposes. It is recommended that you use both together.

docs/config_options.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ page:
3131
- [18. `--only-attrs-with-ClassVar-are-treated-as-class-attrs` (shortform: `-oawcv`, default: `False`)](#18---only-attrs-with-classvar-are-treated-as-class-attrs-shortform--oawcv-default-false)
3232
- [19. `--should-document-star-arguments` (shortform: `-sdsa`, default: `True`)](#19---should-document-star-arguments-shortform--sdsa-default-true)
3333
- [20. `--check-style-mismatch` (shortform: `-csm`, default: `False`)](#20---check-style-mismatch-shortform--csm-default-false)
34-
- [21. `--baseline`](#21---baseline)
35-
- [22. `--generate-baseline` (default: `False`)](#22---generate-baseline-default-false)
36-
- [23. `--auto-regenerate-baseline` (shortform: `-arb`, default: `True`)](#23---auto-regenerate-baseline-shortform--arb-default-true)
37-
- [24. `--show-filenames-in-every-violation-message` (shortform: `-sfn`, default: `False`)](#24---show-filenames-in-every-violation-message-shortform--sfn-default-false)
38-
- [25. `--config` (default: `pyproject.toml`)](#25---config-default-pyprojecttoml)
34+
- [21. `--check-arg-defaults` (shortform: `-cad`, default: `False`)](#21---check-arg-defaults-shortform--cad-default-false)
35+
- [22. `--baseline`](#22---baseline)
36+
- [23. `--generate-baseline` (default: `False`)](#23---generate-baseline-default-false)
37+
- [24. `--auto-regenerate-baseline` (shortform: `-arb`, default: `True`)](#24---auto-regenerate-baseline-shortform--arb-default-true)
38+
- [25. `--show-filenames-in-every-violation-message` (shortform: `-sfn`, default: `False`)](#25---show-filenames-in-every-violation-message-shortform--sfn-default-false)
39+
- [26. `--config` (default: `pyproject.toml`)](#26---config-default-pyprojecttoml)
3940

4041
<!--TOC-->
4142

@@ -234,7 +235,13 @@ If True, check that style specified in --style matches the detected style of
234235
the docstring. If there is a mismatch, DOC003 will be reported. Setting this to
235236
False will silence all DOC003 violations.
236237

237-
## 21. `--baseline`
238+
## 21. `--check-arg-defaults` (shortform: `-cad`, default: `False`)
239+
240+
If True, docstring type hints should contain default values consistent with the
241+
function signature. If False, docstring type hints should not contain default
242+
values. (Only applies to numpy style for now.)
243+
244+
## 22. `--baseline`
238245

239246
Baseline allows you to remember the current project state and then show only
240247
new violations, ignoring old ones. This can be very useful when you'd like to
@@ -256,20 +263,20 @@ If `--generate-baseline` is not passed to _pydoclint_ (the default is `False`),
256263
_pydoclint_ will read your baseline file, and ignore all violations specified
257264
in that file.
258265

259-
## 22. `--generate-baseline` (default: `False`)
266+
## 23. `--generate-baseline` (default: `False`)
260267

261268
Required to use with `--baseline` option. If `True`, generate the baseline file
262269
that contains all current violations.
263270

264-
## 23. `--auto-regenerate-baseline` (shortform: `-arb`, default: `True`)
271+
## 24. `--auto-regenerate-baseline` (shortform: `-arb`, default: `True`)
265272

266273
If it's set to True, _pydoclint_ will automatically regenerate the baseline
267274
file every time you fix violations in the baseline and rerun _pydoclint_.
268275

269276
This saves you from having to manually regenerate the baseline file by setting
270277
`--generate-baseline=True` and run _pydoclint_.
271278

272-
## 24. `--show-filenames-in-every-violation-message` (shortform: `-sfn`, default: `False`)
279+
## 25. `--show-filenames-in-every-violation-message` (shortform: `-sfn`, default: `False`)
273280

274281
If False, in the terminal the violation messages are grouped by file names:
275282

@@ -303,7 +310,7 @@ This can be convenient if you would like to click on each violation message and
303310
go to the corresponding line in your IDE. (Note: not all terminal app offers
304311
this functionality.)
305312

306-
## 25. `--config` (default: `pyproject.toml`)
313+
## 26. `--config` (default: `pyproject.toml`)
307314

308315
The full path of the .toml config file that contains the config options. Note
309316
that the command line options take precedence over the .toml file. Look at this

docs/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ Currently, _pydoclint_ supports three docstring styles:
2626
[numpy](https://numpydoc.readthedocs.io/en/latest/format.html),
2727
[Google](https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html),
2828
and
29-
[Sphinx](https://sphinx-rtd-tutorial.readthedocs.io/en/latest/docstrings.html).
29+
[Sphinx](https://sphinx-rtd-tutorial.readthedocs.io/en/latest/docstrings.html),
30+
with some
31+
[minor style deviations](https://jsh9.github.io/pydoclint/style_deviations.html).
3032

3133
Another note: this linter and [pydocstyle](https://github.com/PyCQA/pydocstyle)
3234
serves complementary purposes. It is recommended that you use both together.

docs/notes_for_users.md

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<!--TOC-->
66

7-
- [1. Why is _pydoclint_ so much faster than _darglint_](#1-why-is-pydoclint-so-much-faster-than-darglint)
7+
- [1. Why is _pydoclint_ so much faster than _darglint_, hhe](#1-why-is-pydoclint-so-much-faster-than-darglint-hhe)
88
- [2. Cases that _pydoclint_ is not designed to handle](#2-cases-that-pydoclint-is-not-designed-to-handle)
99
- [3. Notes on writing type hints](#3-notes-on-writing-type-hints)
1010
- [4. Notes on writing Sphinx-style docstrings](#4-notes-on-writing-sphinx-style-docstrings)
@@ -15,7 +15,7 @@
1515

1616
<!--TOC-->
1717

18-
## 1. Why is _pydoclint_ so much faster than _darglint_
18+
## 1. Why is _pydoclint_ so much faster than _darglint_, hhe
1919

2020
Based on the best understanding of the authors of _pydoclint_, here are some
2121
reasons (this may not be an exhaustive list):
@@ -129,51 +129,15 @@ in order to achieve fast linting and reduce ambiguity.
129129

130130
## 4. Notes on writing Sphinx-style docstrings
131131

132-
The
133-
[official Sphinx documentation](https://sphinx-rtd-tutorial.readthedocs.io/en/latest/docstrings.html)
134-
does not explicitly state this, so it is unclear what header to use to specify
135-
the type of what a function yields.
136-
137-
Many people use `rtype`, but the authors of _pydoclint_ find it difficult to
138-
differentiate the type of return value and the type of yield value.
139-
140-
Therefore, _pydoclint_ expects the convention of `ytype` for yield types. This
141-
is actually common practice, as evident from a code search on GitHub:
142-
https://github.com/search?q=%3Aytype%3A+language%3APython&type=code&l=Python
132+
See
133+
[minor style deviations](https://jsh9.github.io/pydoclint/style_deviations.html#sphinx)
134+
for more details.
143135

144136
## 5. Notes for Google-style users
145137

146-
By default, _pydoclint_ checks return type and yield type consistencies, and it
147-
also requires argument types in the docstring. In other words, by _pydoclint_'s
148-
default, this is an acceptable Google-style docstring:
149-
150-
```python
151-
"""
152-
This is a function.
153-
154-
Args:
155-
arg1 (int): Arg 1
156-
arg2 (float): Arg 2
157-
arg3 (Optional[Union[float, int, str]]): Arg 3
158-
159-
Returns:
160-
int: Result
161-
"""
162-
```
163-
164-
However, this may not be the convention of a lot of Google-style docstring
165-
writers.
166-
167-
But do not worry: here are some config options to tweak:
168-
169-
- `--arg-type-hints-in-docstring`: you can set it to `False`
170-
- `--check-return-types`: you can set it to `False`
171-
- `--check-yield-types`: you can set it to `False`
172-
173-
[Here](https://jsh9.github.io/pydoclint/config_options.html) are all the
174-
configurable options of _pydoclint_, and
175-
[here](https://jsh9.github.io/pydoclint/how_to_config.html) is how to configure
176-
_pydoclint_.
138+
See
139+
[minor style deviations](https://jsh9.github.io/pydoclint/style_deviations.html#google)
140+
for more details.
177141

178142
## 6. How to adopt _pydoclint_ more easily in legacy projects
179143

0 commit comments

Comments
 (0)