diff --git a/CHANGELOG.md b/CHANGELOG.md index 0040a6b..9828fb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +## [0.8.4] - 2026-3-13 + +- Added + - A new config option `--skip-checking-private-functions` (shortform: + `-scpf`) so docstrings in private methods can be skipped +- Full diff + - https://github.com/jsh9/pydoclint/compare/0.8.3...0.8.4 + ## [0.8.3] - 2025-11-26 - Added diff --git a/docs/config_options.md b/docs/config_options.md index 5afd47b..6d01a19 100644 --- a/docs/config_options.md +++ b/docs/config_options.md @@ -20,27 +20,28 @@ ______________________________________________________________________ - [5. `--check-arg-order` (shortform: `-ao`, default: `True`)](#5---check-arg-order-shortform--ao-default-true) - [6. `--skip-checking-short-docstrings` (shortform: `-scsd`, default: `True`)](#6---skip-checking-short-docstrings-shortform--scsd-default-true) - [7. `--skip-checking-raises` (shortform: `-scr`, default: `False`)](#7---skip-checking-raises-shortform--scr-default-false) -- [8. `--allow-init-docstring` (shortform: `-aid`, default: `False`)](#8---allow-init-docstring-shortform--aid-default-false) -- [9. `--require-return-section-when-returning-nothing` (shortform: `-rrs`, default: `False`)](#9---require-return-section-when-returning-nothing-shortform--rrs-default-false) -- [10. `--check-return-types` (shortform: `-crt`, default: `True`)](#10---check-return-types-shortform--crt-default-true) -- [11. `--require-yield-section-when-yielding-nothing` (shortform: `-rys`, default: `True`)](#11---require-yield-section-when-yielding-nothing-shortform--rys-default-true) -- [12. `--check-yield-types` (shortform: `-cyt`, default: `True`)](#12---check-yield-types-shortform--cyt-default-true) -- [13. `--ignore-underscore-args` (shortform: `-iua`, default: `True`)](#13---ignore-underscore-args-shortform--iua-default-true) -- [14. `--ignore-private-args` (shortform: `-ipa`, default: `False`)](#14---ignore-private-args-shortform--ipa-default-false) -- [15. `--check-class-attributes` (shortform: `-cca`, default: `True`)](#15---check-class-attributes-shortform--cca-default-true) -- [16. `--should-document-private-class-attributes` (shortform: `-sdpca`, default: `False`)](#16---should-document-private-class-attributes-shortform--sdpca-default-false) -- [17. `--treat-property-methods-as-class-attributes` (shortform: `-tpmaca`, default: `False`)](#17---treat-property-methods-as-class-attributes-shortform--tpmaca-default-false) -- [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) -- [19. `--should-document-star-arguments` (shortform: `-sdsa`, default: `True`)](#19---should-document-star-arguments-shortform--sdsa-default-true) -- [20. `--omit-stars-when-documenting-varargs` (shortform: `-oswdv`, default: `False`)](#20---omit-stars-when-documenting-varargs-shortform--oswdv-default-false) -- [21. `--check-style-mismatch` (shortform: `-csm`, default: `False`)](#21---check-style-mismatch-shortform--csm-default-false) -- [22. `--check-arg-defaults` (shortform: `-cad`, default: `False`)](#22---check-arg-defaults-shortform--cad-default-false) -- [23. `--baseline`](#23---baseline) -- [24. `--generate-baseline` (default: `False`)](#24---generate-baseline-default-false) -- [25. `--auto-regenerate-baseline` (shortform: `-arb`, default: `True`)](#25---auto-regenerate-baseline-shortform--arb-default-true) -- [26. `--show-filenames-in-every-violation-message` (shortform: `-sfn`, default: `False`)](#26---show-filenames-in-every-violation-message-shortform--sfn-default-false) -- [27. `--native-mode-noqa-location` (shortform: `-nmnl`, default: `docstring`)](#27---native-mode-noqa-location-shortform--nmnl-default-docstring) -- [28. `--config` (default: `pyproject.toml`)](#28---config-default-pyprojecttoml) +- [8. `--skip-checking-private-functions` (shortform: `-scpf`, default: `False`)](#8---skip-checking-private-functions-shortform--scpf-default-false) +- [9. `--allow-init-docstring` (shortform: `-aid`, default: `False`)](#9---allow-init-docstring-shortform--aid-default-false) +- [10. `--require-return-section-when-returning-nothing` (shortform: `-rrs`, default: `False`)](#10---require-return-section-when-returning-nothing-shortform--rrs-default-false) +- [11. `--check-return-types` (shortform: `-crt`, default: `True`)](#11---check-return-types-shortform--crt-default-true) +- [12. `--require-yield-section-when-yielding-nothing` (shortform: `-rys`, default: `True`)](#12---require-yield-section-when-yielding-nothing-shortform--rys-default-true) +- [13. `--check-yield-types` (shortform: `-cyt`, default: `True`)](#13---check-yield-types-shortform--cyt-default-true) +- [14. `--ignore-underscore-args` (shortform: `-iua`, default: `True`)](#14---ignore-underscore-args-shortform--iua-default-true) +- [15. `--ignore-private-args` (shortform: `-ipa`, default: `False`)](#15---ignore-private-args-shortform--ipa-default-false) +- [16. `--check-class-attributes` (shortform: `-cca`, default: `True`)](#16---check-class-attributes-shortform--cca-default-true) +- [17. `--should-document-private-class-attributes` (shortform: `-sdpca`, default: `False`)](#17---should-document-private-class-attributes-shortform--sdpca-default-false) +- [18. `--treat-property-methods-as-class-attributes` (shortform: `-tpmaca`, default: `False`)](#18---treat-property-methods-as-class-attributes-shortform--tpmaca-default-false) +- [19. `--only-attrs-with-ClassVar-are-treated-as-class-attrs` (shortform: `-oawcv`, default: `False`)](#19---only-attrs-with-classvar-are-treated-as-class-attrs-shortform--oawcv-default-false) +- [20. `--should-document-star-arguments` (shortform: `-sdsa`, default: `True`)](#20---should-document-star-arguments-shortform--sdsa-default-true) +- [21. `--omit-stars-when-documenting-varargs` (shortform: `-oswdv`, default: `False`)](#21---omit-stars-when-documenting-varargs-shortform--oswdv-default-false) +- [22. `--check-style-mismatch` (shortform: `-csm`, default: `False`)](#22---check-style-mismatch-shortform--csm-default-false) +- [23. `--check-arg-defaults` (shortform: `-cad`, default: `False`)](#23---check-arg-defaults-shortform--cad-default-false) +- [24. `--baseline`](#24---baseline) +- [25. `--generate-baseline` (default: `False`)](#25---generate-baseline-default-false) +- [26. `--auto-regenerate-baseline` (shortform: `-arb`, default: `True`)](#26---auto-regenerate-baseline-shortform--arb-default-true) +- [27. `--show-filenames-in-every-violation-message` (shortform: `-sfn`, default: `False`)](#27---show-filenames-in-every-violation-message-shortform--sfn-default-false) +- [28. `--native-mode-noqa-location` (shortform: `-nmnl`, default: `docstring`)](#28---native-mode-noqa-location-shortform--nmnl-default-docstring) +- [29. `--config` (default: `pyproject.toml`)](#29---config-default-pyprojecttoml) ______________________________________________________________________ @@ -156,7 +157,14 @@ If `True`, _pydoclint_ won't report `DOC501` or `DOC502` if there are `raise` statements in the function/method but there aren't any "raises" sections in the docstring (or vice versa). -## 8. `--allow-init-docstring` (shortform: `-aid`, default: `False`) +## 8. `--skip-checking-private-functions` (shortform: `-scpf`, default: `False`) + +If `True`, _pydoclint_ won't check functions that are private. This includes +all methods with names that start with '`_`' but not methods whose names start +and end with '`__`' (dunder methods). Any methods defined within private +methods are also skipped. + +## 9. `--allow-init-docstring` (shortform: `-aid`, default: `False`) If it is set to `True`, having a docstring for class constructors (`__init__()`) is allowed, and the arguments are expected to be documented @@ -166,29 +174,29 @@ Note: the default is set to `False` because not every class has an `__init__` method (such as classes that inherit from parent classes), but every class must have the `class ClassName` declaration. -## 9. `--require-return-section-when-returning-nothing` (shortform: `-rrs`, default: `False`) +## 10. `--require-return-section-when-returning-nothing` (shortform: `-rrs`, default: `False`) If `False`, a "return" section is not necessary in the docstring if the function implicitly returns `None` (for example, doesn't have a return statement, or has `-> None` as the return annotation) or doesn't return at all (has return type `NoReturn`). -## 10. `--check-return-types` (shortform: `-crt`, default: `True`) +## 11. `--check-return-types` (shortform: `-crt`, default: `True`) If True, check that the type(s) in the docstring return section and the return annotation in the function signature are consistent -## 11. `--require-yield-section-when-yielding-nothing` (shortform: `-rys`, default: `True`) +## 12. `--require-yield-section-when-yielding-nothing` (shortform: `-rys`, default: `True`) If False, a yields section is not needed in docstring if the function yields None. -## 12. `--check-yield-types` (shortform: `-cyt`, default: `True`) +## 13. `--check-yield-types` (shortform: `-cyt`, default: `True`) If True, check that the type(s) in the docstring "yields" section and the return annotation in the function signature are consistent. -## 13. `--ignore-underscore-args` (shortform: `-iua`, default: `True`) +## 14. `--ignore-underscore-args` (shortform: `-iua`, default: `True`) If True, underscore arguments (such as \_, \_\_, ...) in the function signature do not need to appear in the docstring. @@ -196,13 +204,13 @@ do not need to appear in the docstring. Note: "underscore arguments" are not the same as "private arguments" (i.e., "arguments with leading underscores") such as `_a`. -## 14. `--ignore-private-args` (shortform: `-ipa`, default: `False`) +## 15. `--ignore-private-args` (shortform: `-ipa`, default: `False`) If True, private arguments (those with leading underscores in their names but are not purely `_`, `__`, etc.) in the function signature do not need to appear in the docstring. -## 15. `--check-class-attributes` (shortform: `-cca`, default: `True`) +## 16. `--check-class-attributes` (shortform: `-cca`, default: `True`) If True, check the class attributes (defined under the class definition) against the "Attributes" section of the class's docstring. @@ -211,38 +219,38 @@ Please read [this page](https://jsh9.github.io/pydoclint/checking_class_attributes.html) for more instructions. -## 16. `--should-document-private-class-attributes` (shortform: `-sdpca`, default: `False`) +## 17. `--should-document-private-class-attributes` (shortform: `-sdpca`, default: `False`) If True, private class attributes (those that start with leading `_`) should be documented. If False, they should not be documented. -## 17. `--treat-property-methods-as-class-attributes` (shortform: `-tpmaca`, default: `False`) +## 18. `--treat-property-methods-as-class-attributes` (shortform: `-tpmaca`, default: `False`) If True, treat `@property` methods as class properties. This means that they need to be documented in the "Attributes" section of the class docstring, and there cannot be any docstring under the @property methods. This option is only effective when --check-class-attributes is True. -## 18. `--only-attrs-with-ClassVar-are-treated-as-class-attrs` (shortform: `-oawcv`, default: `False`) +## 19. `--only-attrs-with-ClassVar-are-treated-as-class-attrs` (shortform: `-oawcv`, default: `False`) If True, only the attributes whose type annotations are wrapped within `ClassVar` (where `ClassVar` is imported from `typing`) are treated as class attributes, and all other attributes are treated as instance attributes. -## 19. `--should-document-star-arguments` (shortform: `-sdsa`, default: `True`) +## 20. `--should-document-star-arguments` (shortform: `-sdsa`, default: `True`) If True, "star arguments" (such as `*args`, `**kwargs`, `**props`, etc.) in the function signature should be documented in the docstring. If False, they should not appear in the docstring. -## 20. `--omit-stars-when-documenting-varargs` (shortform: `-oswdv`, default: `False`) +## 21. `--omit-stars-when-documenting-varargs` (shortform: `-oswdv`, default: `False`) If True, docstring argument entries describing `*args` or `**kwargs` may omit the leading `*`, and pydoclint will still match them against the function signature. Leave this disabled to require docstrings to include the leading `*` characters for varargs. -## 21. `--check-style-mismatch` (shortform: `-csm`, default: `False`) +## 22. `--check-style-mismatch` (shortform: `-csm`, default: `False`) If True, check that style specified in --style matches the detected style of the docstring. If there is a mismatch, `DOC003` will be reported. Setting this @@ -251,13 +259,13 @@ to False will silence all `DOC003` violations. Read more about this config option and `DOC003` at [https://jsh9.github.io/pydoclint/style_mismatch.html](https://jsh9.github.io/pydoclint/style_mismatch.html). -## 22. `--check-arg-defaults` (shortform: `-cad`, default: `False`) +## 23. `--check-arg-defaults` (shortform: `-cad`, default: `False`) If True, docstring type hints should contain default values consistent with the function signature. If False, docstring type hints should not contain default values. (Only applies to numpy style for now.) -## 23. `--baseline` +## 24. `--baseline` Baseline allows you to remember the current project state and then show only new violations, ignoring old ones. This can be very useful when you'd like to @@ -279,12 +287,12 @@ If `--generate-baseline` is not passed to _pydoclint_ (the default is `False`), _pydoclint_ will read your baseline file, and ignore all violations specified in that file. -## 24. `--generate-baseline` (default: `False`) +## 25. `--generate-baseline` (default: `False`) Required to use with `--baseline` option. If `True`, generate the baseline file that contains all current violations. -## 25. `--auto-regenerate-baseline` (shortform: `-arb`, default: `True`) +## 26. `--auto-regenerate-baseline` (shortform: `-arb`, default: `True`) If it's set to True, _pydoclint_ will automatically regenerate the baseline file every time you fix violations in the baseline and rerun _pydoclint_. @@ -292,7 +300,7 @@ file every time you fix violations in the baseline and rerun _pydoclint_. This saves you from having to manually regenerate the baseline file by setting `--generate-baseline=True` and run _pydoclint_. -## 26. `--show-filenames-in-every-violation-message` (shortform: `-sfn`, default: `False`) +## 27. `--show-filenames-in-every-violation-message` (shortform: `-sfn`, default: `False`) If False, in the terminal the violation messages are grouped by file names: @@ -326,7 +334,7 @@ This can be convenient if you would like to click on each violation message and go to the corresponding line in your IDE. (Note: not all terminal app offers this functionality.) -## 27. `--native-mode-noqa-location` (shortform: `-nmnl`, default: `docstring`) +## 28. `--native-mode-noqa-location` (shortform: `-nmnl`, default: `docstring`) This option controls where _pydoclint_ looks for inline `# noqa: DOCxxx` comments when running in native mode (i.e., outside of Flake8). Two values are @@ -341,7 +349,7 @@ Only DOC-prefixed violation codes are honored; other codes are ignored by the native parser. This setting has no effect in Flake8 mode, which is controlled by Flake8's own `noqa` handling. -## 28. `--config` (default: `pyproject.toml`) +## 29. `--config` (default: `pyproject.toml`) The full path of the .toml config file that contains the config options. Note that the command line options take precedence over the .toml file. Look at this diff --git a/pydoclint/flake8_entry.py b/pydoclint/flake8_entry.py index e3af644..3f8e1b3 100644 --- a/pydoclint/flake8_entry.py +++ b/pydoclint/flake8_entry.py @@ -103,6 +103,14 @@ def add_options(cls, parser: Any) -> None: # noqa: D102 ' "raise" statements' ), ) + parser.add_option( + '-scpf', + '--skip-checking-private-functions', + action='store', + default='False', + parse_from_config=True, + help='If True, skip checking docstrings of private functions.', + ) parser.add_option( '-aid', '--allow-init-docstring', @@ -323,6 +331,9 @@ def parse_options(cls, options: Any) -> None: # noqa: D102 options.skip_checking_short_docstrings ) cls.skip_checking_raises = options.skip_checking_raises + cls.skip_checking_private_functions = ( + options.skip_checking_private_functions + ) cls.allow_init_docstring = options.allow_init_docstring cls.require_return_section_when_returning_none = ( options.require_return_section_when_returning_none @@ -396,6 +407,10 @@ def run(self) -> Generator[tuple[int, int, str, Any], None, None]: '--skip-checking-raises', self.skip_checking_raises, ) + skipCheckingPrivateFunctions = self._bool( + '--skip-checking-private-functions', + self.skip_checking_private_functions, + ) allowInitDocstring = self._bool( '--allow-init-docstring', self.allow_init_docstring, @@ -469,6 +484,7 @@ def run(self) -> Generator[tuple[int, int, str, Any], None, None]: checkArgOrder=checkArgOrder, skipCheckingShortDocstrings=skipCheckingShortDocstrings, skipCheckingRaises=skipCheckingRaises, + skipCheckingPrivateFunctions=skipCheckingPrivateFunctions, allowInitDocstring=allowInitDocstring, requireReturnSectionWhenReturningNothing=( requireReturnSectionWhenReturningNothing diff --git a/pydoclint/main.py b/pydoclint/main.py index 9826a9a..36fd028 100644 --- a/pydoclint/main.py +++ b/pydoclint/main.py @@ -151,6 +151,14 @@ def validateNativeModeNoqaLocation( ' statements' ), ) +@click.option( + '-scpf', + '--skip-checking-private-functions', + type=bool, + show_default=True, + default=False, + help='If True, skip checking docstrings of private functions.', +) @click.option( '-aid', '--allow-init-docstring', @@ -457,6 +465,7 @@ def main( # noqa: C901, PLR0915 check_arg_order: bool, skip_checking_short_docstrings: bool, skip_checking_raises: bool, + skip_checking_private_functions: bool, allow_init_docstring: bool, check_return_types: bool, check_yield_types: bool, @@ -565,6 +574,7 @@ def main( # noqa: C901, PLR0915 checkArgOrder=check_arg_order, skipCheckingShortDocstrings=skip_checking_short_docstrings, skipCheckingRaises=skip_checking_raises, + skipCheckingPrivateFunctions=skip_checking_private_functions, allowInitDocstring=allow_init_docstring, checkReturnTypes=check_return_types, checkYieldTypes=check_yield_types, @@ -727,6 +737,7 @@ def _checkPaths( checkArgOrder: bool = True, skipCheckingShortDocstrings: bool = True, skipCheckingRaises: bool = False, + skipCheckingPrivateFunctions: bool = False, allowInitDocstring: bool = False, checkReturnTypes: bool = True, checkYieldTypes: bool = True, @@ -783,6 +794,7 @@ def _checkPaths( checkArgOrder=checkArgOrder, skipCheckingShortDocstrings=skipCheckingShortDocstrings, skipCheckingRaises=skipCheckingRaises, + skipCheckingPrivateFunctions=skipCheckingPrivateFunctions, allowInitDocstring=allowInitDocstring, checkReturnTypes=checkReturnTypes, checkYieldTypes=checkYieldTypes, @@ -827,6 +839,7 @@ def _checkFile( checkArgOrder: bool = True, skipCheckingShortDocstrings: bool = True, skipCheckingRaises: bool = False, + skipCheckingPrivateFunctions: bool = False, allowInitDocstring: bool = False, checkReturnTypes: bool = True, checkYieldTypes: bool = True, @@ -878,6 +891,7 @@ def _checkFile( checkArgOrder=checkArgOrder, skipCheckingShortDocstrings=skipCheckingShortDocstrings, skipCheckingRaises=skipCheckingRaises, + skipCheckingPrivateFunctions=skipCheckingPrivateFunctions, allowInitDocstring=allowInitDocstring, checkReturnTypes=checkReturnTypes, checkYieldTypes=checkYieldTypes, diff --git a/pydoclint/utils/generic.py b/pydoclint/utils/generic.py index ce94f35..f512cb6 100644 --- a/pydoclint/utils/generic.py +++ b/pydoclint/utils/generic.py @@ -417,3 +417,25 @@ def stripCommentsFromTypeHints(typeHint: str) -> str: result = typeHint return result + + +def isPrivateVariable(name: str) -> bool: + """ + Return True if ``name`` is considered private. + + A variable is considered private if its name starts with an underscore + ('`_`') but does not start and end with '`__`'. + + Parameters + ---------- + name : str + A variable name + + Returns + ------- + bool + True if ``name`` is private, else False. + """ + return name.startswith('_') and not ( + name.startswith('__') and name.endswith('__') + ) diff --git a/pydoclint/visitor.py b/pydoclint/visitor.py index 60a9ec5..3fe04a3 100644 --- a/pydoclint/visitor.py +++ b/pydoclint/visitor.py @@ -22,6 +22,7 @@ generateFuncMsgPrefix, getDocstring, isLastConstructor, + isPrivateVariable, ) from pydoclint.utils.method_type import MethodType from pydoclint.utils.parse_docstring import ( @@ -73,6 +74,7 @@ def __init__( checkArgOrder: bool = True, skipCheckingShortDocstrings: bool = True, skipCheckingRaises: bool = False, + skipCheckingPrivateFunctions: bool = False, allowInitDocstring: bool = False, checkReturnTypes: bool = True, checkYieldTypes: bool = True, @@ -96,6 +98,7 @@ def __init__( self.checkArgOrder: bool = checkArgOrder self.skipCheckingShortDocstrings: bool = skipCheckingShortDocstrings self.skipCheckingRaises: bool = skipCheckingRaises + self.skipCheckingPrivateFunctions: bool = skipCheckingPrivateFunctions self.allowInitDocstring: bool = allowInitDocstring self.checkReturnTypes: bool = checkReturnTypes self.checkYieldTypes: bool = checkYieldTypes @@ -190,6 +193,10 @@ def visit_FunctionDef(self, node: FuncOrAsyncFuncDef) -> None: # noqa: D102, PL self.parent = parent_ # restore return + if self.skipCheckingPrivateFunctions and isPrivateVariable(node.name): + self.parent = parent_ # restore + return + docstring: str = getDocstring(node) self.isAbstractMethod = checkIsAbstractMethod(node) diff --git a/pyproject.toml b/pyproject.toml index e55ee46..3231605 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2", "wheel"] [project] name = "pydoclint" -version = "0.8.3" +version = "0.8.4" dependencies = [ "click>=8.1.0", "docstring_parser_fork>=0.0.12", diff --git a/tests/test_baseline.py b/tests/test_baseline.py index f478652..a80d9b1 100644 --- a/tests/test_baseline.py +++ b/tests/test_baseline.py @@ -158,9 +158,11 @@ def func2(arg1: str, arg2: list[int]) -> int: expectedNewViolations = [ 'DOC101: Function `bad_docstring_func`: Docstring contains fewer arguments than in function signature.', - 'DOC103: Function `bad_docstring_func`: Docstring arguments are different from function arguments. ' - '(Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the function signature but not in the docstring: [arg1: str, arg2: list[int]].', + ( + 'DOC103: Function `bad_docstring_func`: Docstring arguments are different from function arguments. ' + '(Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [arg1: str, arg2: list[int]].' + ), ] @@ -383,10 +385,12 @@ def testSomeViolationsAreFixedButNewViolationsOccur( tmpFile.as_posix(): [ *expectedNewViolations, 'DOC101: Function `func2`: Docstring contains fewer arguments than in function signature.', - 'DOC103: Function `func2`: Docstring arguments are different' - ' from function arguments. (Or could be other formatting' - ' issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ).' - ' Arguments in the function signature but not in the docstring: [arg2: list[int]].', + ( + 'DOC103: Function `func2`: Docstring arguments are different' + ' from function arguments. (Or could be other formatting' + ' issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ).' + ' Arguments in the function signature but not in the docstring: [arg2: list[int]].' + ), ] } @@ -410,12 +414,16 @@ def testSomeViolationsAreFixedButNewViolationsOccur( } additionalViolations = [ - 'DOC501: Function `bad_docstring_func` has raise statements, but' - ' the docstring does not have a "Raises" section', - 'DOC503: Function `bad_docstring_func` exceptions in the "Raises"' - ' section in the docstring do not match those in the function body.' - ' Raised exceptions in the docstring: []. Raised' - " exceptions in the body: ['ValueError'].", + ( + 'DOC501: Function `bad_docstring_func` has raise statements, but' + ' the docstring does not have a "Raises" section' + ), + ( + 'DOC503: Function `bad_docstring_func` exceptions in the "Raises"' + ' section in the docstring do not match those in the function body.' + ' Raised exceptions in the docstring: []. Raised' + " exceptions in the body: ['ValueError']." + ), ] assert len(remainingViolationsInAllFiles.keys()) == 1 diff --git a/tests/test_data/edge_cases/33_private_functions/case.py b/tests/test_data/edge_cases/33_private_functions/case.py new file mode 100644 index 0000000..d853ffd --- /dev/null +++ b/tests/test_data/edge_cases/33_private_functions/case.py @@ -0,0 +1,50 @@ + +def _test_private_function() -> int: + """test function + + Returns: + bool: With incorrect argument + """ + return 2 + +class TestClass: + """ + Docstring for TestClass, this will still be checked if + skip-checking-short-docstrings is False. + """ + + def __init__(self) -> None: + """This init will still be checked if + skip-checking-short-docstrings is False. + """ + + def _private_method(self, i: int) -> bool: + """Test method + + Args: + i (bool): With incorrect argument type + + Returns: + bool: Always returns False + """ + + def inner_method() -> bool: + """inner method should also be skipped as it is inside a + private method. + + Returns: + int: An incorrect return type. + """ + return False + return inner_method() + + def __private_name_mangled_method(self, i: int) -> bool: + """Name mangled test method + + Args: + i (bool): With incorrect argument type + + Returns: + bool: Always returns False + """ + return False diff --git a/tests/test_edge_cases.py b/tests/test_edge_cases.py index 5d1ff84..e9f2497 100644 --- a/tests/test_edge_cases.py +++ b/tests/test_edge_cases.py @@ -18,33 +18,53 @@ '02/syntax_error_in_type_hints.py', {'style': 'numpy'}, [ - 'DOC106: Function `func1`: The option `--arg-type-hints-in-signature` is ' - '`True` but there are no argument type hints in the signature', - 'DOC107: Function `func1`: The option `--arg-type-hints-in-signature` is ' - '`True` but not all args in the signature have type hints', - 'DOC105: Function `func1`: Argument names match, but type hints in these args ' - 'do not match: a', - 'DOC106: Function `func2`: The option `--arg-type-hints-in-signature` is ' - '`True` but there are no argument type hints in the signature', - 'DOC107: Function `func2`: The option `--arg-type-hints-in-signature` is ' - '`True` but not all args in the signature have type hints', - 'DOC105: Function `func2`: Argument names match, but type hints in these args ' - 'do not match: a', - 'DOC106: Function `func3`: The option `--arg-type-hints-in-signature` is ' - '`True` but there are no argument type hints in the signature', - 'DOC107: Function `func3`: The option `--arg-type-hints-in-signature` is ' - '`True` but not all args in the signature have type hints', - 'DOC105: Function `func3`: Argument names match, but type hints in these args ' - 'do not match: a', + ( + 'DOC106: Function `func1`: The option `--arg-type-hints-in-signature` is ' + '`True` but there are no argument type hints in the signature' + ), + ( + 'DOC107: Function `func1`: The option `--arg-type-hints-in-signature` is ' + '`True` but not all args in the signature have type hints' + ), + ( + 'DOC105: Function `func1`: Argument names match, but type hints in these args ' + 'do not match: a' + ), + ( + 'DOC106: Function `func2`: The option `--arg-type-hints-in-signature` is ' + '`True` but there are no argument type hints in the signature' + ), + ( + 'DOC107: Function `func2`: The option `--arg-type-hints-in-signature` is ' + '`True` but not all args in the signature have type hints' + ), + ( + 'DOC105: Function `func2`: Argument names match, but type hints in these args ' + 'do not match: a' + ), + ( + 'DOC106: Function `func3`: The option `--arg-type-hints-in-signature` is ' + '`True` but there are no argument type hints in the signature' + ), + ( + 'DOC107: Function `func3`: The option `--arg-type-hints-in-signature` is ' + '`True` but not all args in the signature have type hints' + ), + ( + 'DOC105: Function `func3`: Argument names match, but type hints in these args ' + 'do not match: a' + ), ], ), ( '03/union_return_type.py', {'style': 'google'}, [ - 'DOC203: Function `myFunc` return type(s) in docstring not consistent with ' - "the return annotation. Return annotation types: ['str | bool | None']; " - "docstring return section types: ['str | bool | float']" + ( + 'DOC203: Function `myFunc` return type(s) in docstring not consistent with ' + "the return annotation. Return annotation types: ['str | bool | None']; " + "docstring return section types: ['str | bool | float']" + ) ], ), ('04_backticks/google.py', {'style': 'google'}, []), @@ -56,12 +76,16 @@ '06_no_type_hints_in_doc/numpy.py', {'style': 'numpy', 'argTypeHintsInDocstring': False}, [ - 'DOC101: Function `f`: Docstring contains fewer arguments than in function ' - 'signature.', - 'DOC103: Function `f`: Docstring arguments are different from function ' - 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the function signature but not in the docstring: [x: int].', + ( + 'DOC101: Function `f`: Docstring contains fewer arguments than in function ' + 'signature.' + ), + ( + 'DOC103: Function `f`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [x: int].' + ), ], ), ('07_underscore_args/google.py', {'style': 'google'}, []), @@ -71,12 +95,16 @@ '07_underscore_args/google_with_violations.py', {'style': 'google'}, [ - 'DOC101: Function `foo`: Docstring contains fewer arguments than in function ' - 'signature.', - 'DOC103: Function `foo`: Docstring arguments are different from function ' - 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the function signature but not in the docstring: [c: list].', + ( + 'DOC101: Function `foo`: Docstring contains fewer arguments than in function ' + 'signature.' + ), + ( + 'DOC103: Function `foo`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [c: list].' + ), ], ), ('08_return_section_parsing/google.py', {'style': 'google'}, []), @@ -86,14 +114,18 @@ '10_absent_return_anno/numpy.py', {'style': 'numpy'}, [ - 'DOC403: Function `f1` has a "Yields" section in the docstring, but there are ' - 'no "yield" statements, or the return annotation is not a ' - 'Generator/Iterator/Iterable. (Or it could be because the function lacks a ' - 'return annotation.)', - 'DOC404: Function `f1` yield type(s) in docstring not consistent with the ' - 'return annotation. Return annotation does not exist or is not ' - 'Generator[...]/Iterator[...]/Iterable[...], but docstring "yields" section ' - 'has 1 type(s).', + ( + 'DOC403: Function `f1` has a "Yields" section in the docstring, but there are ' + 'no "yield" statements, or the return annotation is not a ' + 'Generator/Iterator/Iterable. (Or it could be because the function lacks a ' + 'return annotation.)' + ), + ( + 'DOC404: Function `f1` yield type(s) in docstring not consistent with the ' + 'return annotation. Return annotation does not exist or is not ' + 'Generator[...]/Iterator[...]/Iterable[...], but docstring "yields" section ' + 'has 1 type(s).' + ), ], ), ( @@ -105,17 +137,21 @@ '11_private_class_attr/google.py', {'style': 'google', 'shouldDocumentPrivateClassAttributes': True}, [ - 'DOC601: Class `MyClass`: Class docstring contains fewer class attributes ' - 'than actual class attributes. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC603: Class `MyClass`: Class docstring attributes are different from ' - 'actual class attributes. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Attributes in the class definition but not in the docstring: [_hidden_attr: ' - 'bool]. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', + ( + 'DOC601: Class `MyClass`: Class docstring contains fewer class attributes ' + 'than actual class attributes. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC603: Class `MyClass`: Class docstring attributes are different from ' + 'actual class attributes. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Attributes in the class definition but not in the docstring: [_hidden_attr: ' + 'bool]. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), ], ), ( @@ -137,17 +173,21 @@ 'shouldDocumentPrivateClassAttributes': False, }, [ - 'DOC602: Class `House`: Class docstring contains more class attributes than ' - 'in actual class attributes. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC603: Class `House`: Class docstring attributes are different from actual ' - 'class attributes. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the docstring but not in the actual class attributes: ' - '[_privateProperty: str]. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', + ( + 'DOC602: Class `House`: Class docstring contains more class attributes than ' + 'in actual class attributes. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC603: Class `House`: Class docstring attributes are different from actual ' + 'class attributes. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the docstring but not in the actual class attributes: ' + '[_privateProperty: str]. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), ], ), ( @@ -159,17 +199,21 @@ 'shouldDocumentPrivateClassAttributes': True, }, [ - 'DOC602: Class `House`: Class docstring contains more class attributes than ' - 'in actual class attributes. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC603: Class `House`: Class docstring attributes are different from actual ' - 'class attributes. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the docstring but not in the actual class attributes: ' - '[_privateProperty: str, price: float]. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', + ( + 'DOC602: Class `House`: Class docstring contains more class attributes than ' + 'in actual class attributes. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC603: Class `House`: Class docstring attributes are different from actual ' + 'class attributes. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the docstring but not in the actual class attributes: ' + '[_privateProperty: str, price: float]. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), ], ), ( @@ -181,17 +225,21 @@ 'shouldDocumentPrivateClassAttributes': False, }, [ - 'DOC602: Class `House`: Class docstring contains more class attributes than ' - 'in actual class attributes. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC603: Class `House`: Class docstring attributes are different from actual ' - 'class attributes. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the docstring but not in the actual class attributes: ' - '[_privateProperty: str, price: float]. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', + ( + 'DOC602: Class `House`: Class docstring contains more class attributes than ' + 'in actual class attributes. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC603: Class `House`: Class docstring attributes are different from actual ' + 'class attributes. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the docstring but not in the actual class attributes: ' + '[_privateProperty: str, price: float]. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), ], ), ( @@ -213,8 +261,10 @@ '14_folders_ending_in_py.py/google.py', {'style': 'google'}, [ - 'DOC105: Function `function1`: Argument names match, but type hints in these ' - 'args do not match: arg1' + ( + 'DOC105: Function `function1`: Argument names match, but type hints in these ' + 'args do not match: arg1' + ) ], ), ('15_very_long_annotations/sphinx.py', {'style': 'sphinx'}, []), @@ -231,39 +281,51 @@ 'onlyAttrsWithClassVarAreTreatedAsClassAttrs': False, }, [ - 'DOC601: Class `AttrsClass`: Class docstring contains fewer class attributes ' - 'than actual class attributes. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC603: Class `AttrsClass`: Class docstring attributes are different from ' - 'actual class attributes. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Attributes in the class definition but not in the docstring: [b: int, d: ' - 'str]. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC601: Class `DataClass`: Class docstring contains fewer class attributes ' - 'than actual class attributes. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC603: Class `DataClass`: Class docstring attributes are different from ' - 'actual class attributes. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Attributes in the class definition but not in the docstring: [f: int, g: ' - 'float, h: str]. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC601: Class `PydanticClass`: Class docstring contains fewer class ' - 'attributes than actual class attributes. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC603: Class `PydanticClass`: Class docstring attributes are different from ' - 'actual class attributes. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Attributes in the class definition but not in the docstring: [j: int, k: ' - 'float, l: str]. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', + ( + 'DOC601: Class `AttrsClass`: Class docstring contains fewer class attributes ' + 'than actual class attributes. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC603: Class `AttrsClass`: Class docstring attributes are different from ' + 'actual class attributes. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Attributes in the class definition but not in the docstring: [b: int, d: ' + 'str]. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC601: Class `DataClass`: Class docstring contains fewer class attributes ' + 'than actual class attributes. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC603: Class `DataClass`: Class docstring attributes are different from ' + 'actual class attributes. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Attributes in the class definition but not in the docstring: [f: int, g: ' + 'float, h: str]. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC601: Class `PydanticClass`: Class docstring contains fewer class ' + 'attributes than actual class attributes. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC603: Class `PydanticClass`: Class docstring attributes are different from ' + 'actual class attributes. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Attributes in the class definition but not in the docstring: [j: int, k: ' + 'float, l: str]. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), ], ), ( @@ -274,21 +336,27 @@ 'onlyAttrsWithClassVarAreTreatedAsClassAttrs': True, }, [ - 'DOC602: Class `AttrsClass`: Class docstring contains more class attributes ' - 'than in actual class attributes. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC603: Class `AttrsClass`: Class docstring attributes are different from ' - 'actual class attributes. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the docstring but not in the actual class attributes: [c: ' - 'float]. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC605: Class `DataClass`: Attribute names match, but type hints in these ' - 'attributes do not match: e (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', + ( + 'DOC602: Class `AttrsClass`: Class docstring contains more class attributes ' + 'than in actual class attributes. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC603: Class `AttrsClass`: Class docstring attributes are different from ' + 'actual class attributes. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the docstring but not in the actual class attributes: [c: ' + 'float]. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC605: Class `DataClass`: Attribute names match, but type hints in these ' + 'attributes do not match: e (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), ], ), ('18_assign_to_subscript/case.py', {}, []), @@ -357,9 +425,11 @@ 'checkReturnTypes': True, }, [ - 'DOC203: Function `my_func_2` return type(s) in docstring not consistent with ' - "the return annotation. Return annotation types: ['None']; docstring return " - "section types: ['']" + ( + 'DOC203: Function `my_func_2` return type(s) in docstring not consistent with ' + "the return annotation. Return annotation types: ['None']; docstring return " + "section types: ['']" + ) ], ), ( @@ -381,12 +451,16 @@ 'checkReturnTypes': True, }, [ - 'DOC404: Function `my_func_1` yield type(s) in docstring not consistent with ' - 'the return annotation. The yield type (the 0th arg in ' - 'Generator[...]/Iterator[...]): int; docstring "yields" section types:', - 'DOC203: Function `my_func_2` return type(s) in docstring not consistent with ' - "the return annotation. Return annotation types: ['None']; docstring return " - "section types: ['']", + ( + 'DOC404: Function `my_func_1` yield type(s) in docstring not consistent with ' + 'the return annotation. The yield type (the 0th arg in ' + 'Generator[...]/Iterator[...]): int; docstring "yields" section types:' + ), + ( + 'DOC203: Function `my_func_2` return type(s) in docstring not consistent with ' + "the return annotation. Return annotation types: ['None']; docstring return " + "section types: ['']" + ), ], ), ( @@ -398,47 +472,65 @@ 'checkReturnTypes': False, }, [ - 'DOC404: Function `my_func_1` yield type(s) in docstring not consistent with ' - 'the return annotation. The yield type (the 0th arg in ' - 'Generator[...]/Iterator[...]): int; docstring "yields" section types:', + ( + 'DOC404: Function `my_func_1` yield type(s) in docstring not consistent with ' + 'the return annotation. The yield type (the 0th arg in ' + 'Generator[...]/Iterator[...]): int; docstring "yields" section types:' + ), ], ), ( '24_star_arguments/numpy.py', {'style': 'numpy', 'shouldDocumentStarArguments': True}, [ - 'DOC101: Function `function_1`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Function `function_1`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the function signature but not in the docstring: [**kwargs: ' - 'Any, *args: Any].', - 'DOC101: Function `function_3`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Function `function_3`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the function signature but not in the docstring: [*args: Any].', + ( + 'DOC101: Function `function_1`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Function `function_1`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [**kwargs: ' + 'Any, *args: Any].' + ), + ( + 'DOC101: Function `function_3`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Function `function_3`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [*args: Any].' + ), ], ), ( '24_star_arguments/numpy.py', {'style': 'numpy', 'shouldDocumentStarArguments': False}, [ - 'DOC102: Function `function_2`: Docstring contains more arguments than in ' - 'function signature.', - 'DOC103: Function `function_2`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the docstring but not in the function signature: [**kwargs: ' - 'Any, *args: Any].', - 'DOC102: Function `function_3`: Docstring contains more arguments than in ' - 'function signature.', - 'DOC103: Function `function_3`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the docstring but not in the function signature: [**kwargs: Any].', + ( + 'DOC102: Function `function_2`: Docstring contains more arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Function `function_2`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the docstring but not in the function signature: [**kwargs: ' + 'Any, *args: Any].' + ), + ( + 'DOC102: Function `function_3`: Docstring contains more arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Function `function_3`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the docstring but not in the function signature: [**kwargs: Any].' + ), ], ), ( @@ -449,13 +541,17 @@ 'argTypeHintsInDocstring': False, }, [ - 'DOC101: Function `function_1`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Function `function_1`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the function signature but not in the docstring: [_: float, __: ' - 'bool, __d: list, _c: dict].', + ( + 'DOC101: Function `function_1`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Function `function_1`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [_: float, __: ' + 'bool, __d: list, _c: dict].' + ), ], ), ( @@ -467,13 +563,17 @@ 'argTypeHintsInDocstring': False, }, [ - 'DOC101: Function `function_1`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Function `function_1`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the function signature but not in the docstring: [_: float, __: ' - 'bool].', + ( + 'DOC101: Function `function_1`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Function `function_1`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [_: float, __: ' + 'bool].' + ), ], ), ( @@ -483,13 +583,17 @@ 'argTypeHintsInDocstring': False, }, [ - 'DOC101: Function `function_1`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Function `function_1`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the function signature but not in the docstring: [__d: list, ' - '_c: dict].', + ( + 'DOC101: Function `function_1`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Function `function_1`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [__d: list, ' + '_c: dict].' + ), ], ), ( @@ -510,16 +614,22 @@ 'checkStyleMismatch': True, }, [ - 'DOC101: Function `funcWithReturnsSection`: Docstring contains fewer ' - 'arguments than in function signature.', - 'DOC103: Function `funcWithReturnsSection`: Docstring arguments are different ' - 'from function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the function signature but not in the docstring: [arg1: str].', - 'DOC003: Function/method `funcWithoutNumpyDashes`: Docstring style mismatch. ' - '(Please read more at https://jsh9.github.io/pydoclint/style_mismatch.html ). ' - 'You specified "numpy" style, but the docstring is likely not written in this ' - 'style.', + ( + 'DOC101: Function `funcWithReturnsSection`: Docstring contains fewer ' + 'arguments than in function signature.' + ), + ( + 'DOC103: Function `funcWithReturnsSection`: Docstring arguments are different ' + 'from function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [arg1: str].' + ), + ( + 'DOC003: Function/method `funcWithoutNumpyDashes`: Docstring style mismatch. ' + '(Please read more at https://jsh9.github.io/pydoclint/style_mismatch.html ). ' + 'You specified "numpy" style, but the docstring is likely not written in this ' + 'style.' + ), ], ), ( @@ -529,36 +639,52 @@ 'checkStyleMismatch': True, }, [ - 'DOC003: Function/method `add1`: Docstring style mismatch. ' - '(Please read more at https://jsh9.github.io/pydoclint/style_mismatch.html ). ' - 'You specified "google" style, but the docstring is likely not written in ' - 'this style.', - 'DOC003: Function/method `add2`: Docstring style mismatch. ' - '(Please read more at https://jsh9.github.io/pydoclint/style_mismatch.html ). ' - 'You specified "google" style, but the docstring is likely not written in ' - 'this style.', - 'DOC003: Function/method `funcWithReturnsSection`: Docstring style mismatch. ' - '(Please read more at https://jsh9.github.io/pydoclint/style_mismatch.html ). ' - 'You specified "google" style, but the docstring is likely not written in ' - 'this style.', - 'DOC101: Function `funcWithReturnsSection`: Docstring contains fewer ' - 'arguments than in function signature.', - 'DOC103: Function `funcWithReturnsSection`: Docstring arguments are different ' - 'from function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the function signature but not in the docstring: [arg1: str].', - 'DOC003: Function/method `funcWithArgsSection`: Docstring style mismatch. ' - '(Please read more at https://jsh9.github.io/pydoclint/style_mismatch.html ). ' - 'You specified "google" style, but the docstring is likely not written in ' - 'this style.', - 'DOC003: Function/method `funcWithExamplesSection`: Docstring style mismatch. ' - '(Please read more at https://jsh9.github.io/pydoclint/style_mismatch.html ). ' - 'You specified "google" style, but the docstring is likely not written in ' - 'this style.', - 'DOC003: Function/method `funcWithNumpyStyleDashes`: Docstring style ' - 'mismatch. (Please read more at ' - 'https://jsh9.github.io/pydoclint/style_mismatch.html ). You specified ' - '"google" style, but the docstring is likely not written in this style.', + ( + 'DOC003: Function/method `add1`: Docstring style mismatch. ' + '(Please read more at https://jsh9.github.io/pydoclint/style_mismatch.html ). ' + 'You specified "google" style, but the docstring is likely not written in ' + 'this style.' + ), + ( + 'DOC003: Function/method `add2`: Docstring style mismatch. ' + '(Please read more at https://jsh9.github.io/pydoclint/style_mismatch.html ). ' + 'You specified "google" style, but the docstring is likely not written in ' + 'this style.' + ), + ( + 'DOC003: Function/method `funcWithReturnsSection`: Docstring style mismatch. ' + '(Please read more at https://jsh9.github.io/pydoclint/style_mismatch.html ). ' + 'You specified "google" style, but the docstring is likely not written in ' + 'this style.' + ), + ( + 'DOC101: Function `funcWithReturnsSection`: Docstring contains fewer ' + 'arguments than in function signature.' + ), + ( + 'DOC103: Function `funcWithReturnsSection`: Docstring arguments are different ' + 'from function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [arg1: str].' + ), + ( + 'DOC003: Function/method `funcWithArgsSection`: Docstring style mismatch. ' + '(Please read more at https://jsh9.github.io/pydoclint/style_mismatch.html ). ' + 'You specified "google" style, but the docstring is likely not written in ' + 'this style.' + ), + ( + 'DOC003: Function/method `funcWithExamplesSection`: Docstring style mismatch. ' + '(Please read more at https://jsh9.github.io/pydoclint/style_mismatch.html ). ' + 'You specified "google" style, but the docstring is likely not written in ' + 'this style.' + ), + ( + 'DOC003: Function/method `funcWithNumpyStyleDashes`: Docstring style ' + 'mismatch. (Please read more at ' + 'https://jsh9.github.io/pydoclint/style_mismatch.html ). You specified ' + '"google" style, but the docstring is likely not written in this style.' + ), ], ), ( @@ -568,10 +694,12 @@ 'skipCheckingShortDocstrings': True, }, [ - 'DOC404: Function `test_yield_with_typing_no_args` yield type(s) in docstring ' - 'not consistent with the return annotation. The yield type (the 0th arg in ' - 'Generator[...]/Iterator[...]): Generator[typing.Any]; docstring "yields" ' - 'section types: Generator123[typing.Any]' + ( + 'DOC404: Function `test_yield_with_typing_no_args` yield type(s) in docstring ' + 'not consistent with the return annotation. The yield type (the 0th arg in ' + 'Generator[...]/Iterator[...]): Generator[typing.Any]; docstring "yields" ' + 'section types: Generator123[typing.Any]' + ) ], ), ( @@ -582,9 +710,11 @@ 'checkArgDefaults': True, }, [ - 'DOC105: Function `regular_function`: Argument names match, but type hints in ' - 'these args do not match: param4 . (Note: docstring arg defaults should look ' - 'like: `, default=XXX`)' + ( + 'DOC105: Function `regular_function`: Argument names match, but type hints in ' + 'these args do not match: param4 . (Note: docstring arg defaults should look ' + 'like: `, default=XXX`)' + ) ], ), ( @@ -625,6 +755,52 @@ {'style': 'sphinx'}, [], ), + ( + '33_private_functions/case.py', + { + 'style': 'google', + 'skipCheckingPrivateFunctions': False, + 'skipCheckingShortDocstrings': False, + }, + [ + ( + 'DOC203: Function `_test_private_function` return type(s) in docstring not ' + "consistent with the return annotation. Return annotation types: ['int']; " + "docstring return section types: ['bool']" + ), + ( + 'DOC301: Class `TestClass`: __init__() should not have a docstring; ' + 'please combine it with the docstring of the class' + ), + ( + 'DOC105: Method `TestClass._private_method`: Argument names match, but type ' + 'hints in these args do not match: i' + ), + ( + 'DOC203: Function `inner_method` return type(s) in docstring not consistent ' + "with the return annotation. Return annotation types: ['bool']; docstring " + "return section types: ['int']" + ), + ( + 'DOC105: Method `TestClass.__private_name_mangled_method`: Argument names ' + 'match, but type hints in these args do not match: i' + ), + ], + ), + ( + '33_private_functions/case.py', + { + 'style': 'google', + 'skipCheckingPrivateFunctions': True, + 'skipCheckingShortDocstrings': False, + }, + [ + ( + 'DOC301: Class `TestClass`: __init__() should not have a docstring; ' + 'please combine it with the docstring of the class' + ) + ], + ), ], ) def testEdgeCases( diff --git a/tests/test_main.py b/tests/test_main.py index 0a7df3a..93d7769 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -16,85 +16,141 @@ def pythonVersionBelow310() -> bool: expectedViolations_True = [ - 'DOC101: Method `MyClass.func1_3`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Method `MyClass.func1_3`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in ' - 'the docstring: [arg1: str, arg2: list[int]].', - 'DOC102: Method `MyClass.func1_6`: Docstring contains more arguments than in ' - 'function signature.', - 'DOC106: Method `MyClass.func1_6`: The option `--arg-type-hints-in-signature` is `True` ' - 'but there are no argument type hints in the signature', - 'DOC103: Method `MyClass.func1_6`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the docstring but not in the ' - 'function signature: [arg1: int].', - 'DOC101: Method `MyClass.func2`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Method `MyClass.func2`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in ' - 'the docstring: [arg2: float | int | None].', - 'DOC102: Method `MyClass.func3`: Docstring contains more arguments than in ' - 'function signature.', - 'DOC103: Method `MyClass.func3`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the docstring but not in the ' - 'function signature: [arg3: Optional[Union[float, int, str]]].', - 'DOC104: Method `MyClass.func4`: Arguments are the same in the docstring and ' - 'the function signature, but are in a different order.', - 'DOC105: Method `MyClass.func5`: Argument names match, but type hints in these args ' - 'do not match: arg1, arg2', - 'DOC104: Method `MyClass.func6`: Arguments are the same in the docstring and ' - 'the function signature, but are in a different order.', - 'DOC105: Method `MyClass.func6`: Argument names match, but type hints in these args ' - 'do not match: arg1, arg2', - 'DOC101: Function `func72`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Function `func72`: Docstring arguments are different from function ' - 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' - 'docstring: [arg3: list, arg4: tuple, arg5: dict].', + ( + 'DOC101: Method `MyClass.func1_3`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Method `MyClass.func1_3`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in ' + 'the docstring: [arg1: str, arg2: list[int]].' + ), + ( + 'DOC102: Method `MyClass.func1_6`: Docstring contains more arguments than in ' + 'function signature.' + ), + ( + 'DOC106: Method `MyClass.func1_6`: The option `--arg-type-hints-in-signature` is `True` ' + 'but there are no argument type hints in the signature' + ), + ( + 'DOC103: Method `MyClass.func1_6`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the docstring but not in the ' + 'function signature: [arg1: int].' + ), + ( + 'DOC101: Method `MyClass.func2`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Method `MyClass.func2`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in ' + 'the docstring: [arg2: float | int | None].' + ), + ( + 'DOC102: Method `MyClass.func3`: Docstring contains more arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Method `MyClass.func3`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the docstring but not in the ' + 'function signature: [arg3: Optional[Union[float, int, str]]].' + ), + ( + 'DOC104: Method `MyClass.func4`: Arguments are the same in the docstring and ' + 'the function signature, but are in a different order.' + ), + ( + 'DOC105: Method `MyClass.func5`: Argument names match, but type hints in these args ' + 'do not match: arg1, arg2' + ), + ( + 'DOC104: Method `MyClass.func6`: Arguments are the same in the docstring and ' + 'the function signature, but are in a different order.' + ), + ( + 'DOC105: Method `MyClass.func6`: Argument names match, but type hints in these args ' + 'do not match: arg1, arg2' + ), + ( + 'DOC101: Function `func72`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Function `func72`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' + 'docstring: [arg3: list, arg4: tuple, arg5: dict].' + ), ] expectedViolations_False = [ - 'DOC101: Method `MyClass.func1_3`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Method `MyClass.func1_3`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in ' - 'the docstring: [arg1: str, arg2: list[int]].', - 'DOC102: Method `MyClass.func1_6`: Docstring contains more arguments than in ' - 'function signature.', - 'DOC106: Method `MyClass.func1_6`: The option `--arg-type-hints-in-signature` is `True` ' - 'but there are no argument type hints in the signature', - 'DOC103: Method `MyClass.func1_6`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the docstring but not in the ' - 'function signature: [arg1: int].', - 'DOC101: Method `MyClass.func2`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Method `MyClass.func2`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in ' - 'the docstring: [arg2: float | int | None].', - 'DOC102: Method `MyClass.func3`: Docstring contains more arguments than in ' - 'function signature.', - 'DOC103: Method `MyClass.func3`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the docstring but not in the ' - 'function signature: [arg3: Optional[Union[float, int, str]]].', - 'DOC105: Method `MyClass.func5`: Argument names match, but type hints in ' - 'these args do not match: arg1, arg2', - 'DOC105: Method `MyClass.func6`: Argument names match, but type hints in ' - 'these args do not match: arg1, arg2', - 'DOC101: Function `func72`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Function `func72`: Docstring arguments are different from function ' - 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' - 'docstring: [arg3: list, arg4: tuple, arg5: dict].', + ( + 'DOC101: Method `MyClass.func1_3`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Method `MyClass.func1_3`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in ' + 'the docstring: [arg1: str, arg2: list[int]].' + ), + ( + 'DOC102: Method `MyClass.func1_6`: Docstring contains more arguments than in ' + 'function signature.' + ), + ( + 'DOC106: Method `MyClass.func1_6`: The option `--arg-type-hints-in-signature` is `True` ' + 'but there are no argument type hints in the signature' + ), + ( + 'DOC103: Method `MyClass.func1_6`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the docstring but not in the ' + 'function signature: [arg1: int].' + ), + ( + 'DOC101: Method `MyClass.func2`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Method `MyClass.func2`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in ' + 'the docstring: [arg2: float | int | None].' + ), + ( + 'DOC102: Method `MyClass.func3`: Docstring contains more arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Method `MyClass.func3`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the docstring but not in the ' + 'function signature: [arg3: Optional[Union[float, int, str]]].' + ), + ( + 'DOC105: Method `MyClass.func5`: Argument names match, but type hints in ' + 'these args do not match: arg1, arg2' + ), + ( + 'DOC105: Method `MyClass.func6`: Argument names match, but type hints in ' + 'these args do not match: arg1, arg2' + ), + ( + 'DOC101: Function `func72`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Function `func72`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' + 'docstring: [arg3: list, arg4: tuple, arg5: dict].' + ), ] expectedViolationsLookup: dict[bool, list[str]] = { @@ -154,104 +210,156 @@ def testClassAttributes( expectedViolations: dict[bool, list[str]] = { True: [ - 'DOC601: Class `MyClass1`: Class docstring contains fewer class attributes ' - 'than actual class attributes. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC603: Class `MyClass1`: Class docstring attributes are different from ' - 'actual class attributes. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Attributes in the class definition but not in the docstring: [hello: int, ' - 'index: pd.DataFrame, world: dict]. Arguments in the docstring but not in the ' - 'actual class attributes: [indices: pd.DataFrame]. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC105: Method `MyClass1.__init__`: Argument names match, but type hints in ' - 'these args do not match: arg1', - 'DOC105: Method `MyClass1.do_something`: Argument names match, but type hints ' - 'in these args do not match: arg2', - 'DOC601: Class `MyClass2`: Class docstring contains fewer class attributes ' - 'than actual class attributes. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC603: Class `MyClass2`: Class docstring attributes are different from ' - 'actual class attributes. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Attributes in the class definition but not in the docstring: [hello: int, ' - 'index: int, world: dict]. Arguments in the docstring but not in the actual ' - 'class attributes: [arg1: float, indices: int]. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC101: Method `MyClass2.__init__`: Docstring contains fewer arguments than ' - 'in function signature.', - 'DOC103: Method `MyClass2.__init__`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the function signature but not in the docstring: [arg1: int].', - 'DOC105: Method `MyClass2.do_something`: Argument names match, but type hints ' - 'in these args do not match: arg2', - 'DOC601: Class `MyClass3`: Class docstring contains fewer class attributes ' - 'than actual class attributes. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC603: Class `MyClass3`: Class docstring attributes are different from ' - 'actual class attributes. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Attributes in the class definition but not in the docstring: [hello: int, ' - 'index: int, name: str, world: dict]. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC102: Method `MyClass3.__init__`: Docstring contains more arguments than ' - 'in function signature.', - 'DOC103: Method `MyClass3.__init__`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the docstring but not in the function signature: [indices: int, ' - 'name: str].', - 'DOC105: Method `MyClass3.do_something`: Argument names match, but type hints ' - 'in these args do not match: arg2', - 'DOC602: Class `MyClass4`: Class docstring contains more class attributes ' - 'than in actual class attributes. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC603: Class `MyClass4`: Class docstring attributes are different from ' - 'actual class attributes. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the docstring but not in the actual class attributes: [name: ' - 'str]. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC605: Class `MyClass8`: Attribute names match, but type hints in these ' - 'attributes do not match: arg2 (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC604: Class `MyClass9`: Attributes are the same in docstring and class ' - 'def, but are in a different order. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', + ( + 'DOC601: Class `MyClass1`: Class docstring contains fewer class attributes ' + 'than actual class attributes. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC603: Class `MyClass1`: Class docstring attributes are different from ' + 'actual class attributes. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Attributes in the class definition but not in the docstring: [hello: int, ' + 'index: pd.DataFrame, world: dict]. Arguments in the docstring but not in the ' + 'actual class attributes: [indices: pd.DataFrame]. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC105: Method `MyClass1.__init__`: Argument names match, but type hints in ' + 'these args do not match: arg1' + ), + ( + 'DOC105: Method `MyClass1.do_something`: Argument names match, but type hints ' + 'in these args do not match: arg2' + ), + ( + 'DOC601: Class `MyClass2`: Class docstring contains fewer class attributes ' + 'than actual class attributes. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC603: Class `MyClass2`: Class docstring attributes are different from ' + 'actual class attributes. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Attributes in the class definition but not in the docstring: [hello: int, ' + 'index: int, world: dict]. Arguments in the docstring but not in the actual ' + 'class attributes: [arg1: float, indices: int]. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC101: Method `MyClass2.__init__`: Docstring contains fewer arguments than ' + 'in function signature.' + ), + ( + 'DOC103: Method `MyClass2.__init__`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [arg1: int].' + ), + ( + 'DOC105: Method `MyClass2.do_something`: Argument names match, but type hints ' + 'in these args do not match: arg2' + ), + ( + 'DOC601: Class `MyClass3`: Class docstring contains fewer class attributes ' + 'than actual class attributes. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC603: Class `MyClass3`: Class docstring attributes are different from ' + 'actual class attributes. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Attributes in the class definition but not in the docstring: [hello: int, ' + 'index: int, name: str, world: dict]. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC102: Method `MyClass3.__init__`: Docstring contains more arguments than ' + 'in function signature.' + ), + ( + 'DOC103: Method `MyClass3.__init__`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the docstring but not in the function signature: [indices: int, ' + 'name: str].' + ), + ( + 'DOC105: Method `MyClass3.do_something`: Argument names match, but type hints ' + 'in these args do not match: arg2' + ), + ( + 'DOC602: Class `MyClass4`: Class docstring contains more class attributes ' + 'than in actual class attributes. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC603: Class `MyClass4`: Class docstring attributes are different from ' + 'actual class attributes. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the docstring but not in the actual class attributes: [name: ' + 'str]. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC605: Class `MyClass8`: Attribute names match, but type hints in these ' + 'attributes do not match: arg2 (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC604: Class `MyClass9`: Attributes are the same in docstring and class ' + 'def, but are in a different order. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), ], False: [ - 'DOC105: Method `MyClass1.__init__`: Argument names match, but type hints in ' - 'these args do not match: arg1', - 'DOC105: Method `MyClass1.do_something`: Argument names match, but type hints ' - 'in these args do not match: arg2', - 'DOC101: Method `MyClass2.__init__`: Docstring contains fewer arguments than ' - 'in function signature.', - 'DOC103: Method `MyClass2.__init__`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the function signature but not in the docstring: [arg1: int].', - 'DOC105: Method `MyClass2.do_something`: Argument names match, but type hints ' - 'in these args do not match: arg2', - 'DOC102: Method `MyClass3.__init__`: Docstring contains more arguments than ' - 'in function signature.', - 'DOC103: Method `MyClass3.__init__`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the docstring but not in the function signature: [indices: int, ' - 'name: str].', - 'DOC105: Method `MyClass3.do_something`: Argument names match, but type hints ' - 'in these args do not match: arg2', + ( + 'DOC105: Method `MyClass1.__init__`: Argument names match, but type hints in ' + 'these args do not match: arg1' + ), + ( + 'DOC105: Method `MyClass1.do_something`: Argument names match, but type hints ' + 'in these args do not match: arg2' + ), + ( + 'DOC101: Method `MyClass2.__init__`: Docstring contains fewer arguments than ' + 'in function signature.' + ), + ( + 'DOC103: Method `MyClass2.__init__`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [arg1: int].' + ), + ( + 'DOC105: Method `MyClass2.do_something`: Argument names match, but type hints ' + 'in these args do not match: arg2' + ), + ( + 'DOC102: Method `MyClass3.__init__`: Docstring contains more arguments than ' + 'in function signature.' + ), + ( + 'DOC103: Method `MyClass3.__init__`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the docstring but not in the function signature: [indices: int, ' + 'name: str].' + ), + ( + 'DOC105: Method `MyClass3.do_something`: Argument names match, but type hints ' + 'in these args do not match: arg2' + ), ], } @@ -270,20 +378,26 @@ def testClassAttributesWithSeparatedDocstrings(style: str) -> None: style=style, ) expectedViolations = [ - 'DOC601: Class `MyClass1`: Class docstring contains fewer class attributes ' - 'than actual class attributes. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC603: Class `MyClass1`: Class docstring attributes are different from ' - 'actual class attributes. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Attributes in the class definition but not in the docstring: [hello: int, ' - 'index: int, world: dict]. Arguments in the docstring but not in the actual ' - 'class attributes: [indices: int]. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC105: Method `MyClass1.__init__`: Argument names match, but type hints in ' - 'these args do not match: arg1', + ( + 'DOC601: Class `MyClass1`: Class docstring contains fewer class attributes ' + 'than actual class attributes. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC603: Class `MyClass1`: Class docstring attributes are different from ' + 'actual class attributes. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Attributes in the class definition but not in the docstring: [hello: int, ' + 'index: int, world: dict]. Arguments in the docstring but not in the actual ' + 'class attributes: [indices: int]. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC105: Method `MyClass1.__init__`: Argument names match, but type hints in ' + 'these args do not match: arg1' + ), ] assert list(map(str, violations)) == expectedViolations @@ -306,35 +420,55 @@ def testReturns(style: str, filename: str) -> None: ) expectedViolations: list[str] = [ - 'DOC201: Method `MyClass.func1_6` does not have a return section in ' - 'docstring', - 'DOC203: Method `MyClass.func1_6` return type(s) in docstring not consistent with ' - 'the return annotation. Return annotation has 1 type(s); docstring ' - 'return section has 0 type(s).', - 'DOC101: Method `MyClass.func2`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Method `MyClass.func2`: Docstring arguments are different from ' - 'function arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in ' - 'the docstring: [arg2: float, arg3: str]. Arguments in the docstring but not ' - 'in the function signature: [arg1: int].', - 'DOC203: Method `MyClass.func2` return type(s) in docstring not consistent with the ' - "return annotation. Return annotation types: ['int | list[float]']; docstring " - "return section types: ['int']", - 'DOC203: Method `MyClass.func4` return type(s) in docstring not consistent with the ' - "return annotation. Return annotation types: ['int']; docstring return " - "section types: ['float']", - 'DOC202: Method `MyClass.func6` has a return section in docstring, but there ' - 'are no return statements or annotations', - 'DOC203: Method `MyClass.func6` return type(s) in docstring not consistent with the ' - 'return annotation. Return annotation has 0 type(s); docstring return section ' - 'has 1 type(s).', - 'DOC203: Method `MyClass.func62` return type(s) in docstring not consistent with the ' - "return annotation. Return annotation types: ['float']; docstring return " - "section types: ['int']", - 'DOC203: Method `MyClass.func7` return type(s) in docstring not consistent with the ' - 'return annotation. Return annotation has 0 type(s); docstring return section ' - 'has 1 type(s).', + ( + 'DOC201: Method `MyClass.func1_6` does not have a return section in ' + 'docstring' + ), + ( + 'DOC203: Method `MyClass.func1_6` return type(s) in docstring not consistent with ' + 'the return annotation. Return annotation has 1 type(s); docstring ' + 'return section has 0 type(s).' + ), + ( + 'DOC101: Method `MyClass.func2`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Method `MyClass.func2`: Docstring arguments are different from ' + 'function arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in ' + 'the docstring: [arg2: float, arg3: str]. Arguments in the docstring but not ' + 'in the function signature: [arg1: int].' + ), + ( + 'DOC203: Method `MyClass.func2` return type(s) in docstring not consistent with the ' + "return annotation. Return annotation types: ['int | list[float]']; docstring " + "return section types: ['int']" + ), + ( + 'DOC203: Method `MyClass.func4` return type(s) in docstring not consistent with the ' + "return annotation. Return annotation types: ['int']; docstring return " + "section types: ['float']" + ), + ( + 'DOC202: Method `MyClass.func6` has a return section in docstring, but there ' + 'are no return statements or annotations' + ), + ( + 'DOC203: Method `MyClass.func6` return type(s) in docstring not consistent with the ' + 'return annotation. Return annotation has 0 type(s); docstring return section ' + 'has 1 type(s).' + ), + ( + 'DOC203: Method `MyClass.func62` return type(s) in docstring not consistent with the ' + "return annotation. Return annotation types: ['float']; docstring return " + "section types: ['int']" + ), + ( + 'DOC203: Method `MyClass.func7` return type(s) in docstring not consistent with the ' + 'return annotation. Return annotation has 0 type(s); docstring return section ' + 'has 1 type(s).' + ), ] if style == 'google': @@ -352,18 +486,26 @@ def testReturns(style: str, filename: str) -> None: ) expectedViolations.extend([ - 'DOC202: Method `MyClass.func101` has a return section in docstring, but ' - 'there are no return statements or annotations', - 'DOC203: Method `MyClass.func101` return type(s) in docstring not consistent ' - 'with the return annotation. Return annotation has 0 type(s); docstring ' - 'return section has 1 type(s).', + ( + 'DOC202: Method `MyClass.func101` has a return section in docstring, but ' + 'there are no return statements or annotations' + ), + ( + 'DOC203: Method `MyClass.func101` return type(s) in docstring not consistent ' + 'with the return annotation. Return annotation has 0 type(s); docstring ' + 'return section has 1 type(s).' + ), 'DOC201: Function `inner101` does not have a return section in docstring', - 'DOC203: Function `inner101` return type(s) in docstring not consistent with ' - 'the return annotation. Return annotation has 1 type(s); docstring return ' - 'section has 0 type(s).', - 'DOC203: Method `MyClass.zipLists1` return type(s) in docstring not consistent with ' - "the return annotation. Return annotation types: ['Iterator[Tuple[Any, " - "Any]]']; docstring return section types: ['Iterator[Tuple[Any, int]]']", + ( + 'DOC203: Function `inner101` return type(s) in docstring not consistent with ' + 'the return annotation. Return annotation has 1 type(s); docstring return ' + 'section has 0 type(s).' + ), + ( + 'DOC203: Method `MyClass.zipLists1` return type(s) in docstring not consistent with ' + "the return annotation. Return annotation types: ['Iterator[Tuple[Any, " + "Any]]']; docstring return section types: ['Iterator[Tuple[Any, int]]']" + ), ]) expectedViolationsCopy = copy.deepcopy(expectedViolations) @@ -396,9 +538,11 @@ def testReturnsPy310plus(style: str, filename: str) -> None: expectedViolations: list[str] = [ 'DOC201: Method `MyClass.func11` does not have a return section in docstring', - 'DOC203: Method `MyClass.func11` return type(s) in docstring not consistent ' - 'with the return annotation. Return annotation has 1 type(s); docstring ' - 'return section has 0 type(s).', + ( + 'DOC203: Method `MyClass.func11` return type(s) in docstring not consistent ' + 'with the return annotation. Return annotation has 1 type(s); docstring ' + 'return section has 0 type(s).' + ), ] expectedViolationsCopy = copy.deepcopy(expectedViolations) @@ -427,9 +571,11 @@ def testReturns_returningNone(style: str, require: bool) -> None: expectedViolationsCopy = ( [ 'DOC201: Function `func` does not have a return section in docstring', - 'DOC203: Function `func` return type(s) in docstring not consistent with the ' - 'return annotation. Return annotation has 1 type(s); docstring return section ' - 'has 0 type(s).', + ( + 'DOC203: Function `func` return type(s) in docstring not consistent with the ' + 'return annotation. Return annotation has 1 type(s); docstring return section ' + 'has 0 type(s).' + ), ] if require else [] @@ -456,9 +602,11 @@ def testReturns_returningNoReturn(style: str, require: bool) -> None: expectedViolationsCopy = ( [ 'DOC201: Function `func` does not have a return section in docstring', - 'DOC203: Function `func` return type(s) in docstring not consistent with the ' - 'return annotation. Return annotation has 1 type(s); docstring return section ' - 'has 0 type(s).', + ( + 'DOC203: Function `func` return type(s) in docstring not consistent with the ' + 'return annotation. Return annotation has 1 type(s); docstring return section ' + 'has 0 type(s).' + ), ] if require else [] @@ -474,60 +622,96 @@ def _tweakViolationMsgForFunctions(expectedViolationsCopy: list[str]) -> None: expected_skipCheckingShortDocstrings_True = [ - 'DOC101: Function `func3`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC106: Function `func3`: The option `--arg-type-hints-in-signature` is `True` ' - 'but there are no argument type hints in the signature', - 'DOC107: Function `func3`: The option `--arg-type-hints-in-signature` is `True` ' - 'but not all args in the signature have type hints', - 'DOC103: Function `func3`: Docstring arguments are different from function ' - 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' - 'docstring: [arg1: , arg2: , arg3: ]. Arguments in the docstring but not in ' - 'the function signature: [var1: int, var2: str].', + ( + 'DOC101: Function `func3`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC106: Function `func3`: The option `--arg-type-hints-in-signature` is `True` ' + 'but there are no argument type hints in the signature' + ), + ( + 'DOC107: Function `func3`: The option `--arg-type-hints-in-signature` is `True` ' + 'but not all args in the signature have type hints' + ), + ( + 'DOC103: Function `func3`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' + 'docstring: [arg1: , arg2: , arg3: ]. Arguments in the docstring but not in ' + 'the function signature: [var1: int, var2: str].' + ), ] expected_skipCheckingShortDocstrings_False = [ - 'DOC101: Function `func1`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC106: Function `func1`: The option `--arg-type-hints-in-signature` is `True` ' - 'but there are no argument type hints in the signature', - 'DOC107: Function `func1`: The option `--arg-type-hints-in-signature` is `True` ' - 'but not all args in the signature have type hints', - 'DOC103: Function `func1`: Docstring arguments are different from function ' - 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the ' - 'function signature but not in the docstring: [arg1: , arg2: , arg3: ].', + ( + 'DOC101: Function `func1`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC106: Function `func1`: The option `--arg-type-hints-in-signature` is `True` ' + 'but there are no argument type hints in the signature' + ), + ( + 'DOC107: Function `func1`: The option `--arg-type-hints-in-signature` is `True` ' + 'but not all args in the signature have type hints' + ), + ( + 'DOC103: Function `func1`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the ' + 'function signature but not in the docstring: [arg1: , arg2: , arg3: ].' + ), 'DOC201: Function `func1` does not have a return section in docstring', - 'DOC203: Function `func1` return type(s) in docstring not consistent with the ' - 'return annotation. Return annotation has 1 type(s); docstring return section ' - 'has 0 type(s).', - 'DOC101: Function `func2`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC106: Function `func2`: The option `--arg-type-hints-in-signature` is `True` ' - 'but there are no argument type hints in the signature', - 'DOC107: Function `func2`: The option `--arg-type-hints-in-signature` is `True` ' - 'but not all args in the signature have type hints', - 'DOC103: Function `func2`: Docstring arguments are different from function ' - 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the ' - 'function signature but not in the docstring: [arg1: , arg2: , arg3: ].', + ( + 'DOC203: Function `func1` return type(s) in docstring not consistent with the ' + 'return annotation. Return annotation has 1 type(s); docstring return section ' + 'has 0 type(s).' + ), + ( + 'DOC101: Function `func2`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC106: Function `func2`: The option `--arg-type-hints-in-signature` is `True` ' + 'but there are no argument type hints in the signature' + ), + ( + 'DOC107: Function `func2`: The option `--arg-type-hints-in-signature` is `True` ' + 'but not all args in the signature have type hints' + ), + ( + 'DOC103: Function `func2`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the ' + 'function signature but not in the docstring: [arg1: , arg2: , arg3: ].' + ), 'DOC201: Function `func2` does not have a return section in docstring', - 'DOC203: Function `func2` return type(s) in docstring not consistent with the ' - 'return annotation. Return annotation has 1 type(s); docstring return section ' - 'has 0 type(s).', - 'DOC101: Function `func3`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC106: Function `func3`: The option `--arg-type-hints-in-signature` is `True` ' - 'but there are no argument type hints in the signature', - 'DOC107: Function `func3`: The option `--arg-type-hints-in-signature` is `True` ' - 'but not all args in the signature have type hints', - 'DOC103: Function `func3`: Docstring arguments are different from function ' - 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the ' - 'function signature but not in the docstring: [arg1: , arg2: , arg3: ]. ' - 'Arguments in the docstring but not in the function signature: [var1: int, ' - 'var2: str].', + ( + 'DOC203: Function `func2` return type(s) in docstring not consistent with the ' + 'return annotation. Return annotation has 1 type(s); docstring return section ' + 'has 0 type(s).' + ), + ( + 'DOC101: Function `func3`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC106: Function `func3`: The option `--arg-type-hints-in-signature` is `True` ' + 'but there are no argument type hints in the signature' + ), + ( + 'DOC107: Function `func3`: The option `--arg-type-hints-in-signature` is `True` ' + 'but not all args in the signature have type hints' + ), + ( + 'DOC103: Function `func3`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the ' + 'function signature but not in the docstring: [arg1: , arg2: , arg3: ]. ' + 'Arguments in the docstring but not in the function signature: [var1: int, ' + 'var2: str].' + ), ] @@ -566,21 +750,33 @@ def testInit(style: str) -> None: style=style, ) expected = [ - 'DOC301: Class `A`: __init__() should not have a docstring; please combine it ' - 'with the docstring of the class', - 'DOC302: Class `B`: The class docstring does not need a "Returns" section, ' - 'because __init__() cannot return anything', - 'DOC105: Method `C.__init__`: Argument names match, but type hints in these ' - 'args do not match: arg2', - 'DOC302: Class `C`: The class docstring does not need a "Returns" section, ' - 'because __init__() cannot return anything', - 'DOC103: Method `D.__init__`: Docstring arguments are different from function ' - 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' - 'docstring: [arg1: int, arg2: float]. Arguments in the docstring but not in ' - 'the function signature: [var1: list, var2: dict].', - 'DOC302: Class `D`: The class docstring does not need a "Returns" section, ' - 'because __init__() cannot return anything', + ( + 'DOC301: Class `A`: __init__() should not have a docstring; please combine it ' + 'with the docstring of the class' + ), + ( + 'DOC302: Class `B`: The class docstring does not need a "Returns" section, ' + 'because __init__() cannot return anything' + ), + ( + 'DOC105: Method `C.__init__`: Argument names match, but type hints in these ' + 'args do not match: arg2' + ), + ( + 'DOC302: Class `C`: The class docstring does not need a "Returns" section, ' + 'because __init__() cannot return anything' + ), + ( + 'DOC103: Method `D.__init__`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' + 'docstring: [arg1: int, arg2: float]. Arguments in the docstring but not in ' + 'the function signature: [var1: list, var2: dict].' + ), + ( + 'DOC302: Class `D`: The class docstring does not need a "Returns" section, ' + 'because __init__() cannot return anything' + ), ] assert list(map(str, violations)) == expected @@ -596,42 +792,68 @@ def testAllowInitDocstring(style: str) -> None: allowInitDocstring=True, ) expected = [ - 'DOC304: Class `A`: Class docstring has an argument/parameter section; please ' - 'put it in the __init__() docstring', - 'DOC302: Class `B`: The class docstring does not need a "Returns" section, ' - 'because __init__() cannot return anything', - 'DOC303: Class `B`: The __init__() docstring does not need a "Returns" ' - 'section, because it cannot return anything', - 'DOC304: Class `B`: Class docstring has an argument/parameter section; please ' - 'put it in the __init__() docstring', - 'DOC302: Class `B`: The class docstring does not need a "Returns" section, ' - 'because __init__() cannot return anything', - 'DOC305: Class `C`: Class docstring has a "Raises" section; please put it in ' - 'the __init__() docstring', - 'DOC503: Method `C.__init__` exceptions in the "Raises" section in the ' - 'docstring do not match those in the function body. Raised exceptions in the ' - "docstring: ['TypeError']. Raised exceptions in the body: ['ValueError'].", - 'DOC306: Class `D`: The class docstring does not need a "Yields" section, ' - 'because __init__() cannot yield anything', - 'DOC307: Class `D`: The __init__() docstring does not need a "Yields" ' - 'section, because __init__() cannot yield anything', - 'DOC306: Class `D`: The class docstring does not need a "Yields" section, ' - 'because __init__() cannot yield anything', - 'DOC403: Method `D.__init__` has a "Yields" section in the docstring, but ' - 'there are no "yield" statements, or the return annotation is not a ' - 'Generator/Iterator/Iterable. (Or it could be because the function lacks a ' - 'return annotation.)', - 'DOC602: Class `E`: Class docstring contains more class attributes than in ' - 'actual class attributes. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', - 'DOC603: Class `E`: Class docstring attributes are different from actual ' - 'class attributes. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the docstring but not in the actual class attributes: [attr1: , ' - 'attr2: ]. (Please read ' - 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' - 'correctly document class attributes.)', + ( + 'DOC304: Class `A`: Class docstring has an argument/parameter section; please ' + 'put it in the __init__() docstring' + ), + ( + 'DOC302: Class `B`: The class docstring does not need a "Returns" section, ' + 'because __init__() cannot return anything' + ), + ( + 'DOC303: Class `B`: The __init__() docstring does not need a "Returns" ' + 'section, because it cannot return anything' + ), + ( + 'DOC304: Class `B`: Class docstring has an argument/parameter section; please ' + 'put it in the __init__() docstring' + ), + ( + 'DOC302: Class `B`: The class docstring does not need a "Returns" section, ' + 'because __init__() cannot return anything' + ), + ( + 'DOC305: Class `C`: Class docstring has a "Raises" section; please put it in ' + 'the __init__() docstring' + ), + ( + 'DOC503: Method `C.__init__` exceptions in the "Raises" section in the ' + 'docstring do not match those in the function body. Raised exceptions in the ' + "docstring: ['TypeError']. Raised exceptions in the body: ['ValueError']." + ), + ( + 'DOC306: Class `D`: The class docstring does not need a "Yields" section, ' + 'because __init__() cannot yield anything' + ), + ( + 'DOC307: Class `D`: The __init__() docstring does not need a "Yields" ' + 'section, because __init__() cannot yield anything' + ), + ( + 'DOC306: Class `D`: The class docstring does not need a "Yields" section, ' + 'because __init__() cannot yield anything' + ), + ( + 'DOC403: Method `D.__init__` has a "Yields" section in the docstring, but ' + 'there are no "yield" statements, or the return annotation is not a ' + 'Generator/Iterator/Iterable. (Or it could be because the function lacks a ' + 'return annotation.)' + ), + ( + 'DOC602: Class `E`: Class docstring contains more class attributes than in ' + 'actual class attributes. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), + ( + 'DOC603: Class `E`: Class docstring attributes are different from actual ' + 'class attributes. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the docstring but not in the actual class attributes: [attr1: , ' + 'attr2: ]. (Please read ' + 'https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to ' + 'correctly document class attributes.)' + ), ] assert list(map(str, violations)) == expected @@ -644,81 +866,133 @@ def testYields(style: str) -> None: style=style, ) expected = [ - 'DOC402: Method `A.method1` has "yield" statements, but the docstring does ' - 'not have a "Yields" section', - 'DOC404: Method `A.method1` yield type(s) in docstring not consistent with ' - 'the return annotation. Return annotation exists, but docstring "yields" ' - 'section does not exist or has 0 type(s).', - 'DOC402: Method `A.method2` has "yield" statements, but the docstring does ' - 'not have a "Yields" section', - 'DOC404: Method `A.method2` yield type(s) in docstring not consistent with ' - 'the return annotation. Return annotation exists, but docstring "yields" ' - 'section does not exist or has 0 type(s).', - 'DOC403: Method `A.method3` has a "Yields" section in the docstring, but ' - 'there are no "yield" statements, or the return annotation is not a ' - 'Generator/Iterator/Iterable. (Or it could be because the function lacks a ' - 'return annotation.)', - 'DOC402: Method `A.method6` has "yield" statements, but the docstring does ' - 'not have a "Yields" section', - 'DOC404: Method `A.method6` yield type(s) in docstring not consistent with ' - 'the return annotation. Return annotation exists, but docstring "yields" ' - 'section does not exist or has 0 type(s).', - 'DOC402: Method `A.method8a` has "yield" statements, but the docstring does ' - 'not have a "Yields" section', - 'DOC404: Method `A.method8a` yield type(s) in docstring not consistent with ' - 'the return annotation. Return annotation exists, but docstring "yields" ' - 'section does not exist or has 0 type(s).', - 'DOC402: Method `A.method8b` has "yield" statements, but the docstring does ' - 'not have a "Yields" section', - 'DOC404: Method `A.method8b` yield type(s) in docstring not consistent with ' - 'the return annotation. Return annotation exists, but docstring "yields" ' - 'section does not exist or has 0 type(s).', - 'DOC402: Method `A.method8c` has "yield" statements, but the docstring does ' - 'not have a "Yields" section', - 'DOC404: Method `A.method8c` yield type(s) in docstring not consistent with ' - 'the return annotation. Return annotation exists, but docstring "yields" ' - 'section does not exist or has 0 type(s).', - 'DOC402: Method `A.method8d` has "yield" statements, but the docstring does ' - 'not have a "Yields" section', - 'DOC404: Method `A.method8d` yield type(s) in docstring not consistent with ' - 'the return annotation. Return annotation exists, but docstring "yields" ' - 'section does not exist or has 0 type(s).', + ( + 'DOC402: Method `A.method1` has "yield" statements, but the docstring does ' + 'not have a "Yields" section' + ), + ( + 'DOC404: Method `A.method1` yield type(s) in docstring not consistent with ' + 'the return annotation. Return annotation exists, but docstring "yields" ' + 'section does not exist or has 0 type(s).' + ), + ( + 'DOC402: Method `A.method2` has "yield" statements, but the docstring does ' + 'not have a "Yields" section' + ), + ( + 'DOC404: Method `A.method2` yield type(s) in docstring not consistent with ' + 'the return annotation. Return annotation exists, but docstring "yields" ' + 'section does not exist or has 0 type(s).' + ), + ( + 'DOC403: Method `A.method3` has a "Yields" section in the docstring, but ' + 'there are no "yield" statements, or the return annotation is not a ' + 'Generator/Iterator/Iterable. (Or it could be because the function lacks a ' + 'return annotation.)' + ), + ( + 'DOC402: Method `A.method6` has "yield" statements, but the docstring does ' + 'not have a "Yields" section' + ), + ( + 'DOC404: Method `A.method6` yield type(s) in docstring not consistent with ' + 'the return annotation. Return annotation exists, but docstring "yields" ' + 'section does not exist or has 0 type(s).' + ), + ( + 'DOC402: Method `A.method8a` has "yield" statements, but the docstring does ' + 'not have a "Yields" section' + ), + ( + 'DOC404: Method `A.method8a` yield type(s) in docstring not consistent with ' + 'the return annotation. Return annotation exists, but docstring "yields" ' + 'section does not exist or has 0 type(s).' + ), + ( + 'DOC402: Method `A.method8b` has "yield" statements, but the docstring does ' + 'not have a "Yields" section' + ), + ( + 'DOC404: Method `A.method8b` yield type(s) in docstring not consistent with ' + 'the return annotation. Return annotation exists, but docstring "yields" ' + 'section does not exist or has 0 type(s).' + ), + ( + 'DOC402: Method `A.method8c` has "yield" statements, but the docstring does ' + 'not have a "Yields" section' + ), + ( + 'DOC404: Method `A.method8c` yield type(s) in docstring not consistent with ' + 'the return annotation. Return annotation exists, but docstring "yields" ' + 'section does not exist or has 0 type(s).' + ), + ( + 'DOC402: Method `A.method8d` has "yield" statements, but the docstring does ' + 'not have a "Yields" section' + ), + ( + 'DOC404: Method `A.method8d` yield type(s) in docstring not consistent with ' + 'the return annotation. Return annotation exists, but docstring "yields" ' + 'section does not exist or has 0 type(s).' + ), 'DOC201: Method `A.zipLists2` does not have a return section in docstring', - 'DOC403: Method `A.zipLists2` has a "Yields" section in the docstring, but ' - 'there are no "yield" statements, or the return annotation is not a ' - 'Generator/Iterator/Iterable. (Or it could be because the function lacks a ' - 'return annotation.)', - 'DOC404: Function `inner9a` yield type(s) in docstring not consistent with ' - 'the return annotation. The yield type (the 0th arg in ' - 'Generator[...]/Iterator[...]): str; docstring "yields" section types: ' - 'Iterable[str]', - 'DOC402: Function `inner9b` has "yield" statements, but the docstring does ' - 'not have a "Yields" section', - 'DOC404: Function `inner9b` yield type(s) in docstring not consistent with ' - 'the return annotation. Return annotation exists, but docstring "yields" ' - 'section does not exist or has 0 type(s).', + ( + 'DOC403: Method `A.zipLists2` has a "Yields" section in the docstring, but ' + 'there are no "yield" statements, or the return annotation is not a ' + 'Generator/Iterator/Iterable. (Or it could be because the function lacks a ' + 'return annotation.)' + ), + ( + 'DOC404: Function `inner9a` yield type(s) in docstring not consistent with ' + 'the return annotation. The yield type (the 0th arg in ' + 'Generator[...]/Iterator[...]): str; docstring "yields" section types: ' + 'Iterable[str]' + ), + ( + 'DOC402: Function `inner9b` has "yield" statements, but the docstring does ' + 'not have a "Yields" section' + ), + ( + 'DOC404: Function `inner9b` yield type(s) in docstring not consistent with ' + 'the return annotation. Return annotation exists, but docstring "yields" ' + 'section does not exist or has 0 type(s).' + ), 'DOC201: Method `A.method9c` does not have a return section in docstring', - 'DOC403: Method `A.method9c` has a "Yields" section in the docstring, but ' - 'there are no "yield" statements, or the return annotation is not a ' - 'Generator/Iterator/Iterable. (Or it could be because the function lacks a ' - 'return annotation.)', - 'DOC404: Function `inner9c` yield type(s) in docstring not consistent with ' - 'the return annotation. The yield type (the 0th arg in ' - 'Generator[...]/Iterator[...]): str; docstring "yields" section types: ' - 'Iterable[str]', - 'DOC402: Method `A.method9d` has "yield" statements, but the docstring does ' - 'not have a "Yields" section', - 'DOC404: Method `A.method9d` yield type(s) in docstring not consistent with ' - 'the return annotation. Return annotation exists, but docstring "yields" ' - 'section does not exist or has 0 type(s).', - 'DOC402: Function `inner9d` has "yield" statements, but the docstring does ' - 'not have a "Yields" section', - 'DOC404: Function `inner9d` yield type(s) in docstring not consistent with ' - 'the return annotation. Return annotation exists, but docstring "yields" ' - 'section does not exist or has 0 type(s).', - 'DOC404: Method `A.method10a` yield type(s) in docstring not consistent with ' - 'the return annotation. The yield type (the 0th arg in ' - 'Generator[...]/Iterator[...]): str; docstring "yields" section types: int', + ( + 'DOC403: Method `A.method9c` has a "Yields" section in the docstring, but ' + 'there are no "yield" statements, or the return annotation is not a ' + 'Generator/Iterator/Iterable. (Or it could be because the function lacks a ' + 'return annotation.)' + ), + ( + 'DOC404: Function `inner9c` yield type(s) in docstring not consistent with ' + 'the return annotation. The yield type (the 0th arg in ' + 'Generator[...]/Iterator[...]): str; docstring "yields" section types: ' + 'Iterable[str]' + ), + ( + 'DOC402: Method `A.method9d` has "yield" statements, but the docstring does ' + 'not have a "Yields" section' + ), + ( + 'DOC404: Method `A.method9d` yield type(s) in docstring not consistent with ' + 'the return annotation. Return annotation exists, but docstring "yields" ' + 'section does not exist or has 0 type(s).' + ), + ( + 'DOC402: Function `inner9d` has "yield" statements, but the docstring does ' + 'not have a "Yields" section' + ), + ( + 'DOC404: Function `inner9d` yield type(s) in docstring not consistent with ' + 'the return annotation. Return annotation exists, but docstring "yields" ' + 'section does not exist or has 0 type(s).' + ), + ( + 'DOC404: Method `A.method10a` yield type(s) in docstring not consistent with ' + 'the return annotation. The yield type (the 0th arg in ' + 'Generator[...]/Iterator[...]): str; docstring "yields" section types: int' + ), ] assert list(map(str, violations)) == expected @@ -735,11 +1009,15 @@ def testYieldsPy310plus(style: str) -> None: style=style, ) expected = [ - 'DOC402: Method `A.func10` has "yield" statements, but the docstring does not ' - 'have a "Yields" section', - 'DOC404: Method `A.func10` yield type(s) in docstring not consistent with the ' - 'return annotation. Return annotation exists, but docstring "yields" section ' - 'does not exist or has 0 type(s).', + ( + 'DOC402: Method `A.func10` has "yield" statements, but the docstring does not ' + 'have a "Yields" section' + ), + ( + 'DOC404: Method `A.func10` yield type(s) in docstring not consistent with the ' + 'return annotation. Return annotation exists, but docstring "yields" section ' + 'does not exist or has 0 type(s).' + ), ] assert list(map(str, violations)) == expected @@ -756,33 +1034,47 @@ def testReturnAndYield(style: str) -> None: style=style, ) expected = [ - 'DOC405: Function `func2` has both "return" and "yield" statements. Please ' - 'use Generator[YieldType, SendType, ReturnType] as the return type ' - 'annotation, and put your yield type in YieldType and return type in ' - 'ReturnType. More details in ' - 'https://jsh9.github.io/pydoclint/notes_generator_vs_iterator.html', - 'DOC203: Function `func3` return type(s) in docstring not consistent with the ' - "return annotation. Return annotation types: ['float']; docstring return " - "section types: ['str']", - 'DOC404: Function `func3` yield type(s) in docstring not consistent with the ' - 'return annotation. The yield type (the 0th arg in ' - 'Generator[...]/Iterator[...]): bool; docstring "yields" section types: int', - 'DOC203: Function `func4` return type(s) in docstring not consistent with the ' - "return annotation. Return annotation types: ['Generator']; docstring return " - "section types: ['str']", - 'DOC404: Function `func4` yield type(s) in docstring not consistent with the ' - 'return annotation. The yield type (the 0th arg in ' - 'Generator[...]/Iterator[...]): Generator; docstring "yields" section types: ' - 'int', - 'DOC405: Function `func5` has both "return" and "yield" statements. Please ' - 'use Generator[YieldType, SendType, ReturnType] as the return type ' - 'annotation, and put your yield type in YieldType and return type in ' - 'ReturnType. More details in ' - 'https://jsh9.github.io/pydoclint/notes_generator_vs_iterator.html', - 'DOC404: Function `func5` yield type(s) in docstring not consistent with the ' - 'return annotation. The yield type (the 0th arg in ' - 'Generator[...]/Iterator[...]): Iterator; docstring "yields" section types: ' - 'int', + ( + 'DOC405: Function `func2` has both "return" and "yield" statements. Please ' + 'use Generator[YieldType, SendType, ReturnType] as the return type ' + 'annotation, and put your yield type in YieldType and return type in ' + 'ReturnType. More details in ' + 'https://jsh9.github.io/pydoclint/notes_generator_vs_iterator.html' + ), + ( + 'DOC203: Function `func3` return type(s) in docstring not consistent with the ' + "return annotation. Return annotation types: ['float']; docstring return " + "section types: ['str']" + ), + ( + 'DOC404: Function `func3` yield type(s) in docstring not consistent with the ' + 'return annotation. The yield type (the 0th arg in ' + 'Generator[...]/Iterator[...]): bool; docstring "yields" section types: int' + ), + ( + 'DOC203: Function `func4` return type(s) in docstring not consistent with the ' + "return annotation. Return annotation types: ['Generator']; docstring return " + "section types: ['str']" + ), + ( + 'DOC404: Function `func4` yield type(s) in docstring not consistent with the ' + 'return annotation. The yield type (the 0th arg in ' + 'Generator[...]/Iterator[...]): Generator; docstring "yields" section types: ' + 'int' + ), + ( + 'DOC405: Function `func5` has both "return" and "yield" statements. Please ' + 'use Generator[YieldType, SendType, ReturnType] as the return type ' + 'annotation, and put your yield type in YieldType and return type in ' + 'ReturnType. More details in ' + 'https://jsh9.github.io/pydoclint/notes_generator_vs_iterator.html' + ), + ( + 'DOC404: Function `func5` yield type(s) in docstring not consistent with the ' + 'return annotation. The yield type (the 0th arg in ' + 'Generator[...]/Iterator[...]): Iterator; docstring "yields" section types: ' + 'int' + ), ] assert list(map(str, violations)) == expected @@ -810,55 +1102,87 @@ def testRaises( style=style, ) expected0 = [ - 'DOC501: Method `B.func1` has raise statements, but the docstring does not ' - 'have a "Raises" section', - 'DOC503: Method `B.func1` exceptions in the "Raises" section in the docstring ' - 'do not match those in the function body. Raised exceptions in the docstring: []. ' - "Raised exceptions in the body: ['ValueError'].", - 'DOC503: Method `B.func4` exceptions in the "Raises" section in the docstring ' - 'do not match those in the function body. Raised exceptions in the docstring: ' - "['CurtomError']. Raised exceptions in the body: ['CustomError'].", - 'DOC502: Method `B.func5` has a "Raises" section in the docstring, but there ' - 'are not "raise" statements in the body', - 'DOC502: Method `B.func7` has a "Raises" section in the docstring, but there ' - 'are not "raise" statements in the body', - 'DOC502: Method `B.func9a` has a "Raises" section in the docstring, but there ' - 'are not "raise" statements in the body', - 'DOC501: Function `inner9a` has raise statements, but the docstring does ' - 'not have a "Raises" section', - 'DOC503: Function `inner9a` exceptions in the "Raises" section in the ' - 'docstring do not match those in the function body. Raised exceptions in the ' - "docstring: []. Raised exceptions in the body: ['FileNotFoundError'].", - 'DOC503: Method `B.func11` exceptions in the "Raises" section in the ' - 'docstring do not match those in the function body. Raised exceptions in the ' - "docstring: ['TypeError']. Raised exceptions in the body: ['TypeError', " - "'ValueError'].", - 'DOC503: Method `B.func13` exceptions in the "Raises" section in the ' - 'docstring do not match those in the function body. Raised exceptions in the ' - "docstring: ['ValueError', 'ValueError']. Raised exceptions in the body: " - "['ValueError'].", - 'DOC503: Method `B.func14` exceptions in the "Raises" section in the ' - 'docstring do not match those in the function body. Raised exceptions in the ' - "docstring: ['CustomError']. Raised exceptions in the body: " - "['exceptions.CustomError'].", - 'DOC503: Method `B.func15` exceptions in the "Raises" section in the ' - 'docstring do not match those in the function body. Raised exceptions in the ' - "docstring: ['CustomError']. Raised exceptions in the body: " - "['exceptions.m.CustomError'].", + ( + 'DOC501: Method `B.func1` has raise statements, but the docstring does not ' + 'have a "Raises" section' + ), + ( + 'DOC503: Method `B.func1` exceptions in the "Raises" section in the docstring ' + 'do not match those in the function body. Raised exceptions in the docstring: []. ' + "Raised exceptions in the body: ['ValueError']." + ), + ( + 'DOC503: Method `B.func4` exceptions in the "Raises" section in the docstring ' + 'do not match those in the function body. Raised exceptions in the docstring: ' + "['CurtomError']. Raised exceptions in the body: ['CustomError']." + ), + ( + 'DOC502: Method `B.func5` has a "Raises" section in the docstring, but there ' + 'are not "raise" statements in the body' + ), + ( + 'DOC502: Method `B.func7` has a "Raises" section in the docstring, but there ' + 'are not "raise" statements in the body' + ), + ( + 'DOC502: Method `B.func9a` has a "Raises" section in the docstring, but there ' + 'are not "raise" statements in the body' + ), + ( + 'DOC501: Function `inner9a` has raise statements, but the docstring does ' + 'not have a "Raises" section' + ), + ( + 'DOC503: Function `inner9a` exceptions in the "Raises" section in the ' + 'docstring do not match those in the function body. Raised exceptions in the ' + "docstring: []. Raised exceptions in the body: ['FileNotFoundError']." + ), + ( + 'DOC503: Method `B.func11` exceptions in the "Raises" section in the ' + 'docstring do not match those in the function body. Raised exceptions in the ' + "docstring: ['TypeError']. Raised exceptions in the body: ['TypeError', " + "'ValueError']." + ), + ( + 'DOC503: Method `B.func13` exceptions in the "Raises" section in the ' + 'docstring do not match those in the function body. Raised exceptions in the ' + "docstring: ['ValueError', 'ValueError']. Raised exceptions in the body: " + "['ValueError']." + ), + ( + 'DOC503: Method `B.func14` exceptions in the "Raises" section in the ' + 'docstring do not match those in the function body. Raised exceptions in the ' + "docstring: ['CustomError']. Raised exceptions in the body: " + "['exceptions.CustomError']." + ), + ( + 'DOC503: Method `B.func15` exceptions in the "Raises" section in the ' + 'docstring do not match those in the function body. Raised exceptions in the ' + "docstring: ['CustomError']. Raised exceptions in the body: " + "['exceptions.m.CustomError']." + ), ] expectedTrue = [ # for if shouldDeclareAssertErr is True - 'DOC504: Method `B.func19` has assert statements, but the docstring does not ' - 'have a "Raises" section. (Assert statements could raise "AssertError".)' + ( + 'DOC504: Method `B.func19` has assert statements, but the docstring does not ' + 'have a "Raises" section. (Assert statements could raise "AssertError".)' + ) ] expectedFalse = [ # for if shouldDeclareAssertErr is False - 'DOC502: Method `B.func17` has a "Raises" section in the docstring, but there ' - 'are not "raise" statements in the body', - 'DOC502: Method `B.func18` has a "Raises" section in the docstring, but there ' - 'are not "raise" statements in the body', - 'DOC502: Method `B.func20` has a "Raises" section in the docstring, but there ' - 'are not "raise" statements in the body', + ( + 'DOC502: Method `B.func17` has a "Raises" section in the docstring, but there ' + 'are not "raise" statements in the body' + ), + ( + 'DOC502: Method `B.func18` has a "Raises" section in the docstring, but there ' + 'are not "raise" statements in the body' + ), + ( + 'DOC502: Method `B.func20` has a "Raises" section in the docstring, but there ' + 'are not "raise" statements in the body' + ), ] expected1 = [] @@ -894,11 +1218,15 @@ def testRaisesPy310plus(style: str, skipRaisesCheck: bool) -> None: style=style, ) expected0 = [ - 'DOC501: Method `B.func10` has raise statements, but the docstring does not ' - 'have a "Raises" section', - 'DOC503: Method `B.func10` exceptions in the "Raises" section in the ' - 'docstring do not match those in the function body. Raised exceptions in the ' - "docstring: []. Raised exceptions in the body: ['ValueError'].", + ( + 'DOC501: Method `B.func10` has raise statements, but the docstring does not ' + 'have a "Raises" section' + ), + ( + 'DOC503: Method `B.func10` exceptions in the "Raises" section in the ' + 'docstring do not match those in the function body. Raised exceptions in the ' + "docstring: []. Raised exceptions in the body: ['ValueError']." + ), ] expected1 = [] expected = expected1 if skipRaisesCheck else expected0 @@ -912,33 +1240,49 @@ def testStarsInArgumentList(style: str) -> None: style=style, ) expected = [ - 'DOC110: Function `func2`: The option `--arg-type-hints-in-docstring` is `True` ' - 'but not all args in the docstring arg list have type hints', - 'DOC103: Function `func2`: Docstring arguments are different from function ' - 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' - 'docstring: [**kwargs: ]. Arguments in the docstring but not in the function ' - 'signature: [kwargs: ].', - 'DOC110: Function `func4`: The option `--arg-type-hints-in-docstring` is `True` ' - 'but not all args in the docstring arg list have type hints', - 'DOC103: Function `func4`: Docstring arguments are different from function ' - 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' - 'docstring: [*args: ]. Arguments in the docstring but not in the function ' - 'signature: [args: ].', - 'DOC101: Function `func6`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Function `func6`: Docstring arguments are different from function ' - 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' - 'docstring: [**kwargs: , *args: ].', - 'DOC101: Function `func7`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Function `func7`: Docstring arguments are different from function ' - 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the function signature but not in the docstring: [**kwargs: , ' - '*args: ].', + ( + 'DOC110: Function `func2`: The option `--arg-type-hints-in-docstring` is `True` ' + 'but not all args in the docstring arg list have type hints' + ), + ( + 'DOC103: Function `func2`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' + 'docstring: [**kwargs: ]. Arguments in the docstring but not in the function ' + 'signature: [kwargs: ].' + ), + ( + 'DOC110: Function `func4`: The option `--arg-type-hints-in-docstring` is `True` ' + 'but not all args in the docstring arg list have type hints' + ), + ( + 'DOC103: Function `func4`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' + 'docstring: [*args: ]. Arguments in the docstring but not in the function ' + 'signature: [args: ].' + ), + ( + 'DOC101: Function `func6`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Function `func6`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' + 'docstring: [**kwargs: , *args: ].' + ), + ( + 'DOC101: Function `func7`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Function `func7`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [**kwargs: , ' + '*args: ].' + ), ] assert list(map(str, violations)) == expected @@ -964,12 +1308,14 @@ def testStarsInArgumentList3(style: str) -> None: omitStarsWhenDocumentingVarargs=True, ) expected = [ - 'DOC103: Function `func9`: Docstring arguments are different from function' - ' arguments. (Or could be other formatting issues:' - ' https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ).' - ' Arguments in the function signature but not in the' - ' docstring: [*args: int]. Arguments in the docstring but not in the function' - ' signature: [**args: int].', + ( + 'DOC103: Function `func9`: Docstring arguments are different from function' + ' arguments. (Or could be other formatting issues:' + ' https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ).' + ' Arguments in the function signature but not in the' + ' docstring: [*args: int]. Arguments in the docstring but not in the function' + ' signature: [**args: int].' + ), ] assert list(map(str, violations)) == expected @@ -981,16 +1327,22 @@ def testParsingErrors_google() -> None: checkStyleMismatch=True, ) expected = [ - 'DOC001: Class `A`: Potential formatting errors in docstring. Error message: ' - "Expected a colon in 'arg1'.", - 'DOC001: Function/method `__init__`: Potential formatting errors in ' - "docstring. Error message: Expected a colon in 'arg1'. (Note: DOC001 could " - 'trigger other unrelated violations under this function/method too. Please ' - 'fix the docstring formatting first.)', - 'DOC003: Function/method `__init__`: Docstring style mismatch. (Please read ' - 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' - 'specified "google" style, but the docstring is likely not written in this ' - 'style.', + ( + 'DOC001: Class `A`: Potential formatting errors in docstring. Error message: ' + "Expected a colon in 'arg1'." + ), + ( + 'DOC001: Function/method `__init__`: Potential formatting errors in ' + "docstring. Error message: Expected a colon in 'arg1'. (Note: DOC001 could " + 'trigger other unrelated violations under this function/method too. Please ' + 'fix the docstring formatting first.)' + ), + ( + 'DOC003: Function/method `__init__`: Docstring style mismatch. (Please read ' + 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' + 'specified "google" style, but the docstring is likely not written in this ' + 'style.' + ), ] assert list(map(str, violations)) == expected @@ -1014,26 +1366,38 @@ def testParsingErrors_numpy() -> None: checkStyleMismatch=True, ) expected = [ - 'DOC001: Class `A`: Potential formatting errors in docstring. Error message: ' - "Section 'Parameters' is not empty but nothing was parsed.", - 'DOC001: Function/method `__init__`: Potential formatting errors in ' - "docstring. Error message: Section 'Parameters' is not empty but nothing was " - 'parsed. (Note: DOC001 could trigger other unrelated violations under this ' - 'function/method too. Please fix the docstring formatting first.)', - 'DOC001: Function/method `method2`: Potential formatting errors in docstring. ' - "Error message: Section 'Yields' is not empty but nothing was parsed. (Note: " - 'DOC001 could trigger other unrelated violations under this function/method ' - 'too. Please fix the docstring formatting first.)', - 'DOC101: Method `A.method2`: Docstring contains fewer arguments than in ' - 'function signature.', - 'DOC103: Method `A.method2`: Docstring arguments are different from function ' - 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' - 'Arguments in the function signature but not in the docstring: [arg4: ].', - 'DOC003: Function/method `funcWithGoogleStyle`: Docstring style mismatch. ' - '(Please read more at https://jsh9.github.io/pydoclint/style_mismatch.html ' - '). You specified "numpy" style, but the docstring is likely not written ' - 'in this style.', + ( + 'DOC001: Class `A`: Potential formatting errors in docstring. Error message: ' + "Section 'Parameters' is not empty but nothing was parsed." + ), + ( + 'DOC001: Function/method `__init__`: Potential formatting errors in ' + "docstring. Error message: Section 'Parameters' is not empty but nothing was " + 'parsed. (Note: DOC001 could trigger other unrelated violations under this ' + 'function/method too. Please fix the docstring formatting first.)' + ), + ( + 'DOC001: Function/method `method2`: Potential formatting errors in docstring. ' + "Error message: Section 'Yields' is not empty but nothing was parsed. (Note: " + 'DOC001 could trigger other unrelated violations under this function/method ' + 'too. Please fix the docstring formatting first.)' + ), + ( + 'DOC101: Method `A.method2`: Docstring contains fewer arguments than in ' + 'function signature.' + ), + ( + 'DOC103: Method `A.method2`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [arg4: ].' + ), + ( + 'DOC003: Function/method `funcWithGoogleStyle`: Docstring style mismatch. ' + '(Please read more at https://jsh9.github.io/pydoclint/style_mismatch.html ' + '). You specified "numpy" style, but the docstring is likely not written ' + 'in this style.' + ), ] assert list(map(str, violations)) == expected @@ -1044,64 +1408,88 @@ def testParsingErrors_numpy() -> None: ( 'google', [ - 'DOC003: Function/method `func2a`: Docstring style mismatch. (Please read ' - 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' - 'specified "google" style, but the docstring is likely not written in this ' - 'style.', - 'DOC003: Function/method `func2b`: Docstring style mismatch. (Please read ' - 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' - 'specified "google" style, but the docstring is likely not written in this ' - 'style.', - 'DOC003: Function/method `func3a`: Docstring style mismatch. (Please read ' - 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' - 'specified "google" style, but the docstring is likely not written in this ' - 'style.', - 'DOC003: Function/method `func3b`: Docstring style mismatch. (Please read ' - 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' - 'specified "google" style, but the docstring is likely not written in this ' - 'style.', + ( + 'DOC003: Function/method `func2a`: Docstring style mismatch. (Please read ' + 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' + 'specified "google" style, but the docstring is likely not written in this ' + 'style.' + ), + ( + 'DOC003: Function/method `func2b`: Docstring style mismatch. (Please read ' + 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' + 'specified "google" style, but the docstring is likely not written in this ' + 'style.' + ), + ( + 'DOC003: Function/method `func3a`: Docstring style mismatch. (Please read ' + 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' + 'specified "google" style, but the docstring is likely not written in this ' + 'style.' + ), + ( + 'DOC003: Function/method `func3b`: Docstring style mismatch. (Please read ' + 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' + 'specified "google" style, but the docstring is likely not written in this ' + 'style.' + ), ], ), ( 'numpy', [ - 'DOC003: Function/method `func1a`: Docstring style mismatch. (Please read ' - 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' - 'specified "numpy" style, but the docstring is likely not written in this ' - 'style.', - 'DOC003: Function/method `func1b`: Docstring style mismatch. (Please read ' - 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' - 'specified "numpy" style, but the docstring is likely not written in this ' - 'style.', - 'DOC003: Function/method `func3a`: Docstring style mismatch. (Please read ' - 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' - 'specified "numpy" style, but the docstring is likely not written in this ' - 'style.', - 'DOC003: Function/method `func3b`: Docstring style mismatch. (Please read ' - 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' - 'specified "numpy" style, but the docstring is likely not written in this ' - 'style.', + ( + 'DOC003: Function/method `func1a`: Docstring style mismatch. (Please read ' + 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' + 'specified "numpy" style, but the docstring is likely not written in this ' + 'style.' + ), + ( + 'DOC003: Function/method `func1b`: Docstring style mismatch. (Please read ' + 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' + 'specified "numpy" style, but the docstring is likely not written in this ' + 'style.' + ), + ( + 'DOC003: Function/method `func3a`: Docstring style mismatch. (Please read ' + 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' + 'specified "numpy" style, but the docstring is likely not written in this ' + 'style.' + ), + ( + 'DOC003: Function/method `func3b`: Docstring style mismatch. (Please read ' + 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' + 'specified "numpy" style, but the docstring is likely not written in this ' + 'style.' + ), ], ), ( 'sphinx', [ - 'DOC003: Function/method `func1a`: Docstring style mismatch. (Please read ' - 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' - 'specified "sphinx" style, but the docstring is likely not written in this ' - 'style.', - 'DOC003: Function/method `func1b`: Docstring style mismatch. (Please read ' - 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' - 'specified "sphinx" style, but the docstring is likely not written in this ' - 'style.', - 'DOC003: Function/method `func2a`: Docstring style mismatch. (Please read ' - 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' - 'specified "sphinx" style, but the docstring is likely not written in this ' - 'style.', - 'DOC003: Function/method `func2b`: Docstring style mismatch. (Please read ' - 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' - 'specified "sphinx" style, but the docstring is likely not written in this ' - 'style.', + ( + 'DOC003: Function/method `func1a`: Docstring style mismatch. (Please read ' + 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' + 'specified "sphinx" style, but the docstring is likely not written in this ' + 'style.' + ), + ( + 'DOC003: Function/method `func1b`: Docstring style mismatch. (Please read ' + 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' + 'specified "sphinx" style, but the docstring is likely not written in this ' + 'style.' + ), + ( + 'DOC003: Function/method `func2a`: Docstring style mismatch. (Please read ' + 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' + 'specified "sphinx" style, but the docstring is likely not written in this ' + 'style.' + ), + ( + 'DOC003: Function/method `func2b`: Docstring style mismatch. (Please read ' + 'more at https://jsh9.github.io/pydoclint/style_mismatch.html ). You ' + 'specified "sphinx" style, but the docstring is likely not written in this ' + 'style.' + ), ], ), ], @@ -1216,28 +1604,44 @@ def testNoYieldSection(style: str, rys: bool) -> None: ) expected_lookup = { True: [ - 'DOC402: Function `func1` has "yield" statements, but the docstring does not ' - 'have a "Yields" section', - 'DOC404: Function `func1` yield type(s) in docstring not consistent with the ' - 'return annotation. Return annotation exists, but docstring "yields" section ' - 'does not exist or has 0 type(s).', - 'DOC402: Function `func2` has "yield" statements, but the docstring does not ' - 'have a "Yields" section', - 'DOC404: Function `func2` yield type(s) in docstring not consistent with the ' - 'return annotation. Return annotation exists, but docstring "yields" section ' - 'does not exist or has 0 type(s).', - 'DOC402: Function `func3` has "yield" statements, but the docstring does not ' - 'have a "Yields" section', - 'DOC404: Function `func3` yield type(s) in docstring not consistent with the ' - 'return annotation. Return annotation exists, but docstring "yields" section ' - 'does not exist or has 0 type(s).', + ( + 'DOC402: Function `func1` has "yield" statements, but the docstring does not ' + 'have a "Yields" section' + ), + ( + 'DOC404: Function `func1` yield type(s) in docstring not consistent with the ' + 'return annotation. Return annotation exists, but docstring "yields" section ' + 'does not exist or has 0 type(s).' + ), + ( + 'DOC402: Function `func2` has "yield" statements, but the docstring does not ' + 'have a "Yields" section' + ), + ( + 'DOC404: Function `func2` yield type(s) in docstring not consistent with the ' + 'return annotation. Return annotation exists, but docstring "yields" section ' + 'does not exist or has 0 type(s).' + ), + ( + 'DOC402: Function `func3` has "yield" statements, but the docstring does not ' + 'have a "Yields" section' + ), + ( + 'DOC404: Function `func3` yield type(s) in docstring not consistent with the ' + 'return annotation. Return annotation exists, but docstring "yields" section ' + 'does not exist or has 0 type(s).' + ), ], False: [ - 'DOC402: Function `func3` has "yield" statements, but the docstring does not ' - 'have a "Yields" section', - 'DOC404: Function `func3` yield type(s) in docstring not consistent with the ' - 'return annotation. Return annotation exists, but docstring "yields" section ' - 'does not exist or has 0 type(s).', + ( + 'DOC402: Function `func3` has "yield" statements, but the docstring does not ' + 'have a "Yields" section' + ), + ( + 'DOC404: Function `func3` yield type(s) in docstring not consistent with the ' + 'return annotation. Return annotation exists, but docstring "yields" section ' + 'does not exist or has 0 type(s).' + ), ], } assert list(map(str, violations)) == expected_lookup[rys] @@ -1272,20 +1676,30 @@ def testAbstractMethod(style: str, checkReturnTypes: bool) -> None: ) if checkReturnTypes: expected = [ - 'DOC201: Method `AbstractClass.another_abstract_method` does not have a ' - 'return section in docstring', - 'DOC201: Method `AbstractClass.third_abstract_method` does not have a return ' - 'section in docstring', - 'DOC203: Method `AbstractClass.third_abstract_method` return type(s) in ' - 'docstring not consistent with the return annotation. Return annotation has 1 ' - 'type(s); docstring return section has 0 type(s).', + ( + 'DOC201: Method `AbstractClass.another_abstract_method` does not have a ' + 'return section in docstring' + ), + ( + 'DOC201: Method `AbstractClass.third_abstract_method` does not have a return ' + 'section in docstring' + ), + ( + 'DOC203: Method `AbstractClass.third_abstract_method` return type(s) in ' + 'docstring not consistent with the return annotation. Return annotation has 1 ' + 'type(s); docstring return section has 0 type(s).' + ), ] else: expected = [ - 'DOC201: Method `AbstractClass.another_abstract_method` does not have a ' - 'return section in docstring', - 'DOC201: Method `AbstractClass.third_abstract_method` does not have a return ' - 'section in docstring', + ( + 'DOC201: Method `AbstractClass.another_abstract_method` does not have a ' + 'return section in docstring' + ), + ( + 'DOC201: Method `AbstractClass.third_abstract_method` does not have a return ' + 'section in docstring' + ), ] assert list(map(str, violations)) == expected @@ -1300,16 +1714,24 @@ def testNoReturnSectionInPropertyMethod(style: str) -> None: checkClassAttributes=False, ) expected = [ - 'DOC201: Method `MyOtherClass.method_2` does not have a return section in ' - 'docstring', - 'DOC203: Method `MyOtherClass.method_2` return type(s) in docstring not ' - 'consistent with the return annotation. Return annotation has 1 type(s); ' - 'docstring return section has 0 type(s).', - 'DOC201: Method `MyOtherClass.method_3` does not have a return section in ' - 'docstring', - 'DOC203: Method `MyOtherClass.method_3` return type(s) in docstring not ' - 'consistent with the return annotation. Return annotation has 1 type(s); ' - 'docstring return section has 0 type(s).', + ( + 'DOC201: Method `MyOtherClass.method_2` does not have a return section in ' + 'docstring' + ), + ( + 'DOC203: Method `MyOtherClass.method_2` return type(s) in docstring not ' + 'consistent with the return annotation. Return annotation has 1 type(s); ' + 'docstring return section has 0 type(s).' + ), + ( + 'DOC201: Method `MyOtherClass.method_3` does not have a return section in ' + 'docstring' + ), + ( + 'DOC203: Method `MyOtherClass.method_3` return type(s) in docstring not ' + 'consistent with the return annotation. Return annotation has 1 type(s); ' + 'docstring return section has 0 type(s).' + ), ] assert list(map(str, violations)) == expected @@ -1336,108 +1758,204 @@ def testTypeHintChecking( expected_lookup = { (False, False): [ - 'DOC108: Method `MyClass.func2`: The option `--arg-type-hints-in-signature` is ' - '`False` but there are argument type hints in the signature', - 'DOC111: Method `MyClass.func3`: The option `--arg-type-hints-in-docstring` is ' - '`False` but there are type hints in the docstring arg list', - 'DOC108: Method `MyClass.func4`: The option `--arg-type-hints-in-signature` is ' - '`False` but there are argument type hints in the signature', - 'DOC111: Method `MyClass.func4`: The option `--arg-type-hints-in-docstring` is ' - '`False` but there are type hints in the docstring arg list', - 'DOC108: Method `MyClass.func5`: The option `--arg-type-hints-in-signature` is ' - '`False` but there are argument type hints in the signature', - 'DOC111: Method `MyClass.func5`: The option `--arg-type-hints-in-docstring` is ' - '`False` but there are type hints in the docstring arg list', - 'DOC108: Method `MyClass.func6`: The option `--arg-type-hints-in-signature` is ' - '`False` but there are argument type hints in the signature', - 'DOC111: Method `MyClass.func6`: The option `--arg-type-hints-in-docstring` is ' - '`False` but there are type hints in the docstring arg list', - 'DOC108: Method `MyClass.func7`: The option `--arg-type-hints-in-signature` is ' - '`False` but there are argument type hints in the signature', - 'DOC111: Method `MyClass.func7`: The option `--arg-type-hints-in-docstring` is ' - '`False` but there are type hints in the docstring arg list', + ( + 'DOC108: Method `MyClass.func2`: The option `--arg-type-hints-in-signature` is ' + '`False` but there are argument type hints in the signature' + ), + ( + 'DOC111: Method `MyClass.func3`: The option `--arg-type-hints-in-docstring` is ' + '`False` but there are type hints in the docstring arg list' + ), + ( + 'DOC108: Method `MyClass.func4`: The option `--arg-type-hints-in-signature` is ' + '`False` but there are argument type hints in the signature' + ), + ( + 'DOC111: Method `MyClass.func4`: The option `--arg-type-hints-in-docstring` is ' + '`False` but there are type hints in the docstring arg list' + ), + ( + 'DOC108: Method `MyClass.func5`: The option `--arg-type-hints-in-signature` is ' + '`False` but there are argument type hints in the signature' + ), + ( + 'DOC111: Method `MyClass.func5`: The option `--arg-type-hints-in-docstring` is ' + '`False` but there are type hints in the docstring arg list' + ), + ( + 'DOC108: Method `MyClass.func6`: The option `--arg-type-hints-in-signature` is ' + '`False` but there are argument type hints in the signature' + ), + ( + 'DOC111: Method `MyClass.func6`: The option `--arg-type-hints-in-docstring` is ' + '`False` but there are type hints in the docstring arg list' + ), + ( + 'DOC108: Method `MyClass.func7`: The option `--arg-type-hints-in-signature` is ' + '`False` but there are argument type hints in the signature' + ), + ( + 'DOC111: Method `MyClass.func7`: The option `--arg-type-hints-in-docstring` is ' + '`False` but there are type hints in the docstring arg list' + ), ], (False, True): [ - 'DOC106: Method `MyClass.func1`: The option `--arg-type-hints-in-signature` is ' - '`True` but there are no argument type hints in the signature', - 'DOC107: Method `MyClass.func1`: The option `--arg-type-hints-in-signature` is ' - '`True` but not all args in the signature have type hints', - 'DOC106: Method `MyClass.func3`: The option `--arg-type-hints-in-signature` is ' - '`True` but there are no argument type hints in the signature', - 'DOC107: Method `MyClass.func3`: The option `--arg-type-hints-in-signature` is ' - '`True` but not all args in the signature have type hints', - 'DOC111: Method `MyClass.func3`: The option `--arg-type-hints-in-docstring` is ' - '`False` but there are type hints in the docstring arg list', - 'DOC111: Method `MyClass.func4`: The option `--arg-type-hints-in-docstring` is ' - '`False` but there are type hints in the docstring arg list', - 'DOC107: Method `MyClass.func5`: The option `--arg-type-hints-in-signature` is ' - '`True` but not all args in the signature have type hints', - 'DOC111: Method `MyClass.func5`: The option `--arg-type-hints-in-docstring` is ' - '`False` but there are type hints in the docstring arg list', - 'DOC111: Method `MyClass.func6`: The option `--arg-type-hints-in-docstring` is ' - '`False` but there are type hints in the docstring arg list', - 'DOC107: Method `MyClass.func7`: The option `--arg-type-hints-in-signature` is ' - '`True` but not all args in the signature have type hints', - 'DOC111: Method `MyClass.func7`: The option `--arg-type-hints-in-docstring` is ' - '`False` but there are type hints in the docstring arg list', + ( + 'DOC106: Method `MyClass.func1`: The option `--arg-type-hints-in-signature` is ' + '`True` but there are no argument type hints in the signature' + ), + ( + 'DOC107: Method `MyClass.func1`: The option `--arg-type-hints-in-signature` is ' + '`True` but not all args in the signature have type hints' + ), + ( + 'DOC106: Method `MyClass.func3`: The option `--arg-type-hints-in-signature` is ' + '`True` but there are no argument type hints in the signature' + ), + ( + 'DOC107: Method `MyClass.func3`: The option `--arg-type-hints-in-signature` is ' + '`True` but not all args in the signature have type hints' + ), + ( + 'DOC111: Method `MyClass.func3`: The option `--arg-type-hints-in-docstring` is ' + '`False` but there are type hints in the docstring arg list' + ), + ( + 'DOC111: Method `MyClass.func4`: The option `--arg-type-hints-in-docstring` is ' + '`False` but there are type hints in the docstring arg list' + ), + ( + 'DOC107: Method `MyClass.func5`: The option `--arg-type-hints-in-signature` is ' + '`True` but not all args in the signature have type hints' + ), + ( + 'DOC111: Method `MyClass.func5`: The option `--arg-type-hints-in-docstring` is ' + '`False` but there are type hints in the docstring arg list' + ), + ( + 'DOC111: Method `MyClass.func6`: The option `--arg-type-hints-in-docstring` is ' + '`False` but there are type hints in the docstring arg list' + ), + ( + 'DOC107: Method `MyClass.func7`: The option `--arg-type-hints-in-signature` is ' + '`True` but not all args in the signature have type hints' + ), + ( + 'DOC111: Method `MyClass.func7`: The option `--arg-type-hints-in-docstring` is ' + '`False` but there are type hints in the docstring arg list' + ), ], (True, False): [ - 'DOC109: Method `MyClass.func1`: The option `--arg-type-hints-in-docstring` is ' - '`True` but there are no type hints in the docstring arg list', - 'DOC110: Method `MyClass.func1`: The option `--arg-type-hints-in-docstring` is ' - '`True` but not all args in the docstring arg list have type hints', - 'DOC108: Method `MyClass.func2`: The option `--arg-type-hints-in-signature` is ' - '`False` but there are argument type hints in the signature', - 'DOC109: Method `MyClass.func2`: The option `--arg-type-hints-in-docstring` is ' - '`True` but there are no type hints in the docstring arg list', - 'DOC110: Method `MyClass.func2`: The option `--arg-type-hints-in-docstring` is ' - '`True` but not all args in the docstring arg list have type hints', - 'DOC108: Method `MyClass.func4`: The option `--arg-type-hints-in-signature` is ' - '`False` but there are argument type hints in the signature', - 'DOC108: Method `MyClass.func5`: The option `--arg-type-hints-in-signature` is ' - '`False` but there are argument type hints in the signature', - 'DOC110: Method `MyClass.func5`: The option `--arg-type-hints-in-docstring` is ' - '`True` but not all args in the docstring arg list have type hints', - 'DOC108: Method `MyClass.func6`: The option `--arg-type-hints-in-signature` is ' - '`False` but there are argument type hints in the signature', - 'DOC108: Method `MyClass.func7`: The option `--arg-type-hints-in-signature` is ' - '`False` but there are argument type hints in the signature', - 'DOC110: Method `MyClass.func7`: The option `--arg-type-hints-in-docstring` is ' - '`True` but not all args in the docstring arg list have type hints', + ( + 'DOC109: Method `MyClass.func1`: The option `--arg-type-hints-in-docstring` is ' + '`True` but there are no type hints in the docstring arg list' + ), + ( + 'DOC110: Method `MyClass.func1`: The option `--arg-type-hints-in-docstring` is ' + '`True` but not all args in the docstring arg list have type hints' + ), + ( + 'DOC108: Method `MyClass.func2`: The option `--arg-type-hints-in-signature` is ' + '`False` but there are argument type hints in the signature' + ), + ( + 'DOC109: Method `MyClass.func2`: The option `--arg-type-hints-in-docstring` is ' + '`True` but there are no type hints in the docstring arg list' + ), + ( + 'DOC110: Method `MyClass.func2`: The option `--arg-type-hints-in-docstring` is ' + '`True` but not all args in the docstring arg list have type hints' + ), + ( + 'DOC108: Method `MyClass.func4`: The option `--arg-type-hints-in-signature` is ' + '`False` but there are argument type hints in the signature' + ), + ( + 'DOC108: Method `MyClass.func5`: The option `--arg-type-hints-in-signature` is ' + '`False` but there are argument type hints in the signature' + ), + ( + 'DOC110: Method `MyClass.func5`: The option `--arg-type-hints-in-docstring` is ' + '`True` but not all args in the docstring arg list have type hints' + ), + ( + 'DOC108: Method `MyClass.func6`: The option `--arg-type-hints-in-signature` is ' + '`False` but there are argument type hints in the signature' + ), + ( + 'DOC108: Method `MyClass.func7`: The option `--arg-type-hints-in-signature` is ' + '`False` but there are argument type hints in the signature' + ), + ( + 'DOC110: Method `MyClass.func7`: The option `--arg-type-hints-in-docstring` is ' + '`True` but not all args in the docstring arg list have type hints' + ), ], (True, True): [ - 'DOC106: Method `MyClass.func1`: The option `--arg-type-hints-in-signature` is ' - '`True` but there are no argument type hints in the signature', - 'DOC107: Method `MyClass.func1`: The option `--arg-type-hints-in-signature` is ' - '`True` but not all args in the signature have type hints', - 'DOC109: Method `MyClass.func1`: The option `--arg-type-hints-in-docstring` is ' - '`True` but there are no type hints in the docstring arg list', - 'DOC110: Method `MyClass.func1`: The option `--arg-type-hints-in-docstring` is ' - '`True` but not all args in the docstring arg list have type hints', - 'DOC109: Method `MyClass.func2`: The option `--arg-type-hints-in-docstring` is ' - '`True` but there are no type hints in the docstring arg list', - 'DOC110: Method `MyClass.func2`: The option `--arg-type-hints-in-docstring` is ' - '`True` but not all args in the docstring arg list have type hints', - 'DOC105: Method `MyClass.func2`: Argument names match, but type hints in ' - 'these args do not match: arg1, arg2', - 'DOC106: Method `MyClass.func3`: The option `--arg-type-hints-in-signature` is ' - '`True` but there are no argument type hints in the signature', - 'DOC107: Method `MyClass.func3`: The option `--arg-type-hints-in-signature` is ' - '`True` but not all args in the signature have type hints', - 'DOC105: Method `MyClass.func3`: Argument names match, but type hints in ' - 'these args do not match: arg1, arg2', - 'DOC107: Method `MyClass.func5`: The option `--arg-type-hints-in-signature` is ' - '`True` but not all args in the signature have type hints', - 'DOC110: Method `MyClass.func5`: The option `--arg-type-hints-in-docstring` is ' - '`True` but not all args in the docstring arg list have type hints', - 'DOC105: Method `MyClass.func5`: Argument names match, but type hints in ' - 'these args do not match: arg1, arg2', - 'DOC105: Method `MyClass.func6`: Argument names match, but type hints in ' - 'these args do not match: arg1', - 'DOC107: Method `MyClass.func7`: The option `--arg-type-hints-in-signature` is ' - '`True` but not all args in the signature have type hints', - 'DOC110: Method `MyClass.func7`: The option `--arg-type-hints-in-docstring` is ' - '`True` but not all args in the docstring arg list have type hints', + ( + 'DOC106: Method `MyClass.func1`: The option `--arg-type-hints-in-signature` is ' + '`True` but there are no argument type hints in the signature' + ), + ( + 'DOC107: Method `MyClass.func1`: The option `--arg-type-hints-in-signature` is ' + '`True` but not all args in the signature have type hints' + ), + ( + 'DOC109: Method `MyClass.func1`: The option `--arg-type-hints-in-docstring` is ' + '`True` but there are no type hints in the docstring arg list' + ), + ( + 'DOC110: Method `MyClass.func1`: The option `--arg-type-hints-in-docstring` is ' + '`True` but not all args in the docstring arg list have type hints' + ), + ( + 'DOC109: Method `MyClass.func2`: The option `--arg-type-hints-in-docstring` is ' + '`True` but there are no type hints in the docstring arg list' + ), + ( + 'DOC110: Method `MyClass.func2`: The option `--arg-type-hints-in-docstring` is ' + '`True` but not all args in the docstring arg list have type hints' + ), + ( + 'DOC105: Method `MyClass.func2`: Argument names match, but type hints in ' + 'these args do not match: arg1, arg2' + ), + ( + 'DOC106: Method `MyClass.func3`: The option `--arg-type-hints-in-signature` is ' + '`True` but there are no argument type hints in the signature' + ), + ( + 'DOC107: Method `MyClass.func3`: The option `--arg-type-hints-in-signature` is ' + '`True` but not all args in the signature have type hints' + ), + ( + 'DOC105: Method `MyClass.func3`: Argument names match, but type hints in ' + 'these args do not match: arg1, arg2' + ), + ( + 'DOC107: Method `MyClass.func5`: The option `--arg-type-hints-in-signature` is ' + '`True` but not all args in the signature have type hints' + ), + ( + 'DOC110: Method `MyClass.func5`: The option `--arg-type-hints-in-docstring` is ' + '`True` but not all args in the docstring arg list have type hints' + ), + ( + 'DOC105: Method `MyClass.func5`: Argument names match, but type hints in ' + 'these args do not match: arg1, arg2' + ), + ( + 'DOC105: Method `MyClass.func6`: Argument names match, but type hints in ' + 'these args do not match: arg1' + ), + ( + 'DOC107: Method `MyClass.func7`: The option `--arg-type-hints-in-signature` is ' + '`True` but not all args in the signature have type hints' + ), + ( + 'DOC110: Method `MyClass.func7`: The option `--arg-type-hints-in-docstring` is ' + '`True` but not all args in the docstring arg list have type hints' + ), ], } @@ -1480,63 +1998,109 @@ def testArgDefaults( expectedViolationsLookup = { True: [ - 'DOC105: Function `func1`: Argument names match, but type hints in these args ' - 'do not match: arg1, arg2 . (Note: docstring arg defaults should look like: ' - '`, default=XXX`)', - 'DOC105: Function `func4`: Argument names match, but type hints in these args ' - 'do not match: arg1, arg2 . (Note: docstring arg defaults should look like: ' - '`, default=XXX`)', - 'DOC105: Function `func5`: Argument names match, but type hints in these args ' - 'do not match: arg2, arg3 . (Note: docstring arg defaults should look like: ' - '`, default=XXX`)', - 'DOC105: Function `func7`: Argument names match, but type hints in these args ' - 'do not match: arg2 . (Note: docstring arg defaults should look like: `, ' - 'default=XXX`)', - 'DOC105: Method `MyClass.method1`: Argument names match, but type hints in ' - 'these args do not match: arg1, arg2 . (Note: docstring arg defaults should ' - 'look like: `, default=XXX`)', - 'DOC105: Method `MyClass.method3`: Argument names match, but type hints in ' - 'these args do not match: arg1, arg2 . (Note: docstring arg defaults should ' - 'look like: `, default=XXX`)', - 'DOC105: Function `wrong_default_style`: Argument names match, but type hints ' - 'in these args do not match: arg2, arg3, arg4 . (Note: docstring arg defaults ' - 'should look like: `, default=XXX`)', - 'DOC105: Function `default_string_double_quote`: Argument names match, but ' - 'type hints in these args do not match: arg1 . (Note: docstring arg defaults ' - 'should look like: `, default=XXX`)', - 'DOC105: Function `default_string_single_quote`: Argument names match, but ' - 'type hints in these args do not match: arg1 . (Note: docstring arg defaults ' - 'should look like: `, default=XXX`)', + ( + 'DOC105: Function `func1`: Argument names match, but type hints in these args ' + 'do not match: arg1, arg2 . (Note: docstring arg defaults should look like: ' + '`, default=XXX`)' + ), + ( + 'DOC105: Function `func4`: Argument names match, but type hints in these args ' + 'do not match: arg1, arg2 . (Note: docstring arg defaults should look like: ' + '`, default=XXX`)' + ), + ( + 'DOC105: Function `func5`: Argument names match, but type hints in these args ' + 'do not match: arg2, arg3 . (Note: docstring arg defaults should look like: ' + '`, default=XXX`)' + ), + ( + 'DOC105: Function `func7`: Argument names match, but type hints in these args ' + 'do not match: arg2 . (Note: docstring arg defaults should look like: `, ' + 'default=XXX`)' + ), + ( + 'DOC105: Method `MyClass.method1`: Argument names match, but type hints in ' + 'these args do not match: arg1, arg2 . (Note: docstring arg defaults should ' + 'look like: `, default=XXX`)' + ), + ( + 'DOC105: Method `MyClass.method3`: Argument names match, but type hints in ' + 'these args do not match: arg1, arg2 . (Note: docstring arg defaults should ' + 'look like: `, default=XXX`)' + ), + ( + 'DOC105: Function `wrong_default_style`: Argument names match, but type hints ' + 'in these args do not match: arg2, arg3, arg4 . (Note: docstring arg defaults ' + 'should look like: `, default=XXX`)' + ), + ( + 'DOC105: Function `default_string_double_quote`: Argument names match, but ' + 'type hints in these args do not match: arg1 . (Note: docstring arg defaults ' + 'should look like: `, default=XXX`)' + ), + ( + 'DOC105: Function `default_string_single_quote`: Argument names match, but ' + 'type hints in these args do not match: arg1 . (Note: docstring arg defaults ' + 'should look like: `, default=XXX`)' + ), ], False: [ - 'DOC105: Function `func2`: Argument names match, but type hints in these args ' - 'do not match: arg1, arg2', - 'DOC105: Function `func3`: Argument names match, but type hints in these args ' - 'do not match: arg1, arg2', - 'DOC105: Function `func4`: Argument names match, but type hints in these args ' - 'do not match: arg1, arg2', - 'DOC105: Function `func5`: Argument names match, but type hints in these args ' - 'do not match: arg1, arg2', - 'DOC105: Function `func6`: Argument names match, but type hints in these args ' - 'do not match: arg2', - 'DOC105: Method `MyClass.method2`: Argument names match, but type hints in ' - 'these args do not match: arg1, arg2', - 'DOC105: Method `MyClass.method3`: Argument names match, but type hints in ' - 'these args do not match: arg1, arg2', - 'DOC105: Function `func_with_complex_defaults`: Argument names match, but ' - 'type hints in these args do not match: arg2, arg3, arg4', - 'DOC105: Function `func_all_defaults`: Argument names match, but type hints ' - 'in these args do not match: arg1, arg2, arg3', - 'DOC105: Function `func_single_quote_or_double_quote_dont_matter`: Argument ' - 'names match, but type hints in these args do not match: arg1, arg2', - 'DOC105: Function `wrong_default_style`: Argument names match, but type hints ' - 'in these args do not match: arg1, arg2, arg3, arg4', - 'DOC105: Function `space_does_not_matter`: Argument names match, but type ' - 'hints in these args do not match: arg1', - 'DOC105: Function `default_string_double_quote`: Argument names match, but ' - 'type hints in these args do not match: arg1, arg2, arg3', - 'DOC105: Function `default_string_single_quote`: Argument names match, but ' - 'type hints in these args do not match: arg1, arg2, arg3', + ( + 'DOC105: Function `func2`: Argument names match, but type hints in these args ' + 'do not match: arg1, arg2' + ), + ( + 'DOC105: Function `func3`: Argument names match, but type hints in these args ' + 'do not match: arg1, arg2' + ), + ( + 'DOC105: Function `func4`: Argument names match, but type hints in these args ' + 'do not match: arg1, arg2' + ), + ( + 'DOC105: Function `func5`: Argument names match, but type hints in these args ' + 'do not match: arg1, arg2' + ), + ( + 'DOC105: Function `func6`: Argument names match, but type hints in these args ' + 'do not match: arg2' + ), + ( + 'DOC105: Method `MyClass.method2`: Argument names match, but type hints in ' + 'these args do not match: arg1, arg2' + ), + ( + 'DOC105: Method `MyClass.method3`: Argument names match, but type hints in ' + 'these args do not match: arg1, arg2' + ), + ( + 'DOC105: Function `func_with_complex_defaults`: Argument names match, but ' + 'type hints in these args do not match: arg2, arg3, arg4' + ), + ( + 'DOC105: Function `func_all_defaults`: Argument names match, but type hints ' + 'in these args do not match: arg1, arg2, arg3' + ), + ( + 'DOC105: Function `func_single_quote_or_double_quote_dont_matter`: Argument ' + 'names match, but type hints in these args do not match: arg1, arg2' + ), + ( + 'DOC105: Function `wrong_default_style`: Argument names match, but type hints ' + 'in these args do not match: arg1, arg2, arg3, arg4' + ), + ( + 'DOC105: Function `space_does_not_matter`: Argument names match, but type ' + 'hints in these args do not match: arg1' + ), + ( + 'DOC105: Function `default_string_double_quote`: Argument names match, but ' + 'type hints in these args do not match: arg1, arg2, arg3' + ), + ( + 'DOC105: Function `default_string_single_quote`: Argument names match, but ' + 'type hints in these args do not match: arg1, arg2, arg3' + ), ], } diff --git a/tests/utils/test_generic.py b/tests/utils/test_generic.py index 134f29a..276d914 100644 --- a/tests/utils/test_generic.py +++ b/tests/utils/test_generic.py @@ -2,7 +2,12 @@ import pytest -from pydoclint.utils.generic import collectFuncArgs, specialEqual, stripQuotes +from pydoclint.utils.generic import ( + collectFuncArgs, + isPrivateVariable, + specialEqual, + stripQuotes, +) src1 = """ def func1( @@ -112,3 +117,24 @@ def testStripQuotes(string: str, expected: str) -> None: ) def testSpecialEqual(str1: str, str2: str, expected: bool) -> None: assert specialEqual(str1, str2) == expected + + +@pytest.mark.parametrize( + ('name', 'private'), + [ + ('__init__', False), + ('__init_', True), + ('__contains__', False), + ('__contains_', True), + ('__dunder____', False), + ('public_____name__', False), + ('_private_____name_____', True), + ('var', False), + ('_var', True), + ('__var', True), + ('__var_', True), + ('__var__', False), + ], +) +def testIsPrivateVariable(name: str, private: bool) -> None: + assert isPrivateVariable(name) == private