A Python docstring linter that checks arguments, returns, yields, and raises sections
—
Complete command-line tool for docstring linting with extensive configuration options, style detection, and baseline management for gradual adoption in large codebases.
The primary command-line interface for pydoclint with comprehensive configuration options for all aspects of docstring validation.
def main(
ctx: click.Context,
quiet: bool,
exclude: str,
style: str,
paths: tuple[str, ...],
type_hints_in_signature: str,
type_hints_in_docstring: str,
arg_type_hints_in_signature: bool,
arg_type_hints_in_docstring: bool,
check_arg_order: bool,
skip_checking_short_docstrings: bool,
skip_checking_raises: bool,
allow_init_docstring: bool,
check_return_types: bool,
check_yield_types: bool,
ignore_underscore_args: bool,
ignore_private_args: bool,
check_class_attributes: bool,
should_document_private_class_attributes: bool,
treat_property_methods_as_class_attributes: bool,
require_return_section_when_returning_none: bool,
require_return_section_when_returning_nothing: bool,
require_yield_section_when_yielding_nothing: bool,
only_attrs_with_classvar_are_treated_as_class_attrs: bool,
should_document_star_arguments: bool,
should_declare_assert_error_if_assert_statement_exists: bool,
check_style_mismatch: bool,
check_arg_defaults: bool,
generate_baseline: bool,
auto_regenerate_baseline: bool,
baseline: str,
show_filenames_in_every_violation_message: bool,
config: str | None,
) -> None:
"""
Command-line entry point of pydoclint.
Validates Python docstrings against function signatures and implementations
with extensive configuration options for all validation rules.
Parameters:
- ctx: Click context for command-line processing
- quiet: If True, suppress file processing output
- exclude: Regex pattern to exclude files/folders
- style: Docstring style ('numpy', 'google', 'sphinx')
- paths: File/directory paths to check
- arg_type_hints_in_signature: Require type hints in function signatures
- arg_type_hints_in_docstring: Require type hints in docstring arguments
- check_arg_order: Validate argument order consistency
- skip_checking_short_docstrings: Skip validation for short summary-only docstrings
- skip_checking_raises: Skip validation of raises sections
- allow_init_docstring: Allow both __init__ and class docstrings
- check_return_types: Validate return type consistency
- check_yield_types: Validate yield type consistency
- ignore_underscore_args: Ignore underscore arguments (_, __, etc.)
- ignore_private_args: Ignore private arguments (leading underscore)
- check_class_attributes: Validate class attributes against docstrings
- should_document_private_class_attributes: Require private class attrs in docs
- treat_property_methods_as_class_attributes: Treat @property as class attributes
- require_return_section_when_returning_nothing: Require return section for None returns
- require_yield_section_when_yielding_nothing: Require yields section for None yields
- only_attrs_with_classvar_are_treated_as_class_attrs: Only ClassVar attrs as class attrs
- should_document_star_arguments: Require *args/**kwargs in docstrings
- should_declare_assert_error_if_assert_statement_exists: Declare AssertionError for asserts
- check_style_mismatch: Validate style consistency within docstrings
- check_arg_defaults: Validate default values in docstring type hints
- generate_baseline: Generate new baseline file
- auto_regenerate_baseline: Automatically update baseline when violations fixed
- baseline: Path to baseline file for tracking existing violations
- show_filenames_in_every_violation_message: Include filename in each violation
- config: Path to TOML configuration file
Returns:
None (exits with status code 0 for success, 1 for violations found)
"""Validates that the specified docstring style is one of the supported formats.
def validateStyleValue(
context: click.Context,
param: click.Parameter,
value: str | None,
) -> str | None:
"""
Validate the value of the 'style' option.
Parameters:
- context: Click context object
- param: Click parameter object
- value: Style value to validate
Returns:
str | None: Validated style value
Raises:
click.BadParameter: If style is not 'numpy', 'google', or 'sphinx'
"""Internal functions for processing multiple paths and individual files.
def _checkPaths(
paths: tuple[str, ...],
style: str = 'numpy',
argTypeHintsInSignature: bool = True,
argTypeHintsInDocstring: bool = True,
checkArgOrder: bool = True,
skipCheckingShortDocstrings: bool = True,
skipCheckingRaises: bool = False,
allowInitDocstring: bool = False,
checkReturnTypes: bool = True,
checkYieldTypes: bool = True,
ignoreUnderscoreArgs: bool = True,
ignorePrivateArgs: bool = False,
checkClassAttributes: bool = True,
shouldDocumentPrivateClassAttributes: bool = False,
treatPropertyMethodsAsClassAttributes: bool = False,
onlyAttrsWithClassVarAreTreatedAsClassAttrs: bool = False,
requireReturnSectionWhenReturningNothing: bool = False,
requireYieldSectionWhenYieldingNothing: bool = False,
shouldDocumentStarArguments: bool = True,
shouldDeclareAssertErrorIfAssertStatementExists: bool = False,
checkStyleMismatch: bool = False,
checkArgDefaults: bool = False,
quiet: bool = False,
exclude: str = '',
) -> dict[str, list[Violation]]:
"""
Check multiple file/directory paths for docstring violations.
Parameters:
- paths: Tuple of file/directory paths to check
- style: Docstring style to validate against
- (additional parameters match main function)
Returns:
dict[str, list[Violation]]: Mapping of file paths to their violations
"""
def _checkFile(
filename: Path,
style: str = 'numpy',
argTypeHintsInSignature: bool = True,
argTypeHintsInDocstring: bool = True,
checkArgOrder: bool = True,
skipCheckingShortDocstrings: bool = True,
skipCheckingRaises: bool = False,
allowInitDocstring: bool = False,
checkReturnTypes: bool = True,
checkYieldTypes: bool = True,
ignoreUnderscoreArgs: bool = True,
ignorePrivateArgs: bool = False,
checkClassAttributes: bool = True,
shouldDocumentPrivateClassAttributes: bool = False,
treatPropertyMethodsAsClassAttributes: bool = False,
onlyAttrsWithClassVarAreTreatedAsClassAttrs: bool = False,
requireReturnSectionWhenReturningNothing: bool = False,
requireYieldSectionWhenYieldingNothing: bool = False,
shouldDocumentStarArguments: bool = True,
shouldDeclareAssertErrorIfAssertStatementExists: bool = False,
checkStyleMismatch: bool = False,
checkArgDefaults: bool = False,
) -> list[Violation]:
"""
Check a single Python file for docstring violations.
Parameters:
- filename: Path to Python file to check
- (additional parameters match main function)
Returns:
list[Violation]: List of violations found in the file
"""# Check current directory with numpy style
pydoclint .
# Check specific files with google style
pydoclint --style=google src/module.py src/utils.py
# Quiet mode with custom exclusions
pydoclint --quiet --exclude="tests/|migrations/" src/# Comprehensive checking with all features enabled
pydoclint \
--style=numpy \
--check-class-attributes=True \
--check-return-types=True \
--check-yield-types=True \
--should-document-star-arguments=True \
--check-style-mismatch=True \
src/
# Gradual adoption with baseline
pydoclint --generate-baseline --baseline=current-violations.txt src/
pydoclint --baseline=current-violations.txt --auto-regenerate-baseline=True src/# Use custom configuration file
pydoclint --config=custom-config.toml src/
# Configuration in pyproject.toml
[tool.pydoclint]
style = 'google'
exclude = '\.git|tests/'
check-class-attributes = true
require-return-section-when-returning-nothing = trueInstall with Tessl CLI
npx tessl i tessl/pypi-pydoclint