pytools.api.DocValidator#
- class pytools.api.DocValidator(*, root_dir, validate_protected=None, exclude_from_parameter_validation=None, additional_tests=None)[source]#
Validates docstrings and type hints in all Python sources in a given directory tree.
By default, only validates public classes, methods, and functions, and class initializers (
__init__
). Protected classes, methods, and functions are only validated if their name is provided in parametervalidate_protected
.- Parameters
root_dir (
str
) – the root directory of all Python files to be validatedvalidate_protected (
Optional
[Iterable
[str
]]) – names of protected functions and methods to be validated (default:('__init__',)
)exclude_from_parameter_validation (
Union
[str
,Pattern
[str
],None
]) – do not validate parameter documentation and type hints for classes, methods or functions whose full name (including the module prefix) matches the given regular expressionadditional_tests (
Optional
[Iterable
[DocTest
]]) – additional documentation tests to run on each API element
Method summary
Validate documentation, including docstrings and type annotations.
Attribute summary
The default value for parameter
validate_protected
.Default collection of documentation tests to run during validation.
The root directory of all Python files to be validated.
Names of protected functions and methods to be validated.
Names of modules for which parameter documentation and type hints should not be validated.
A dictionary mapping definitions to lists of errors identified during validation.
The documentation tests to run on each definition during validation.
Definitions
- validate_doc()[source]#
Validate documentation, including docstrings and type annotations.
- Return type
- Returns
True
if the validation was successful;False
if the validation failed
- DEFAULT_VALIDATE_PROTECTED = ('__init__',)#
The default value for parameter
validate_protected
.
- DEFAULT_VALIDATION_TESTS: tuple[doc.DocTest, ...] = (HasDocstring(), HasMatchingParameterDoc(), HasWellFormedDocstring(), HasTypeHints())#
Default collection of documentation tests to run during validation.
- exclude_from_parameter_validation: Optional[re.Pattern[str]]#
Names of modules for which parameter documentation and type hints should not be validated.
- validation_errors: dict[str, list[str]]#
A dictionary mapping definitions to lists of errors identified during validation.
- validation_tests: tuple[doc.DocTest, ...]#
The documentation tests to run on each definition during validation.