diff --git a/CHANGELOG.md b/CHANGELOG.md index f50b6bc..a7e2f58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [Unpublished] +## [0.5.10] - 2024-12-07 - Changed - Command line message about loading config file is now hidden with config @@ -10,6 +10,7 @@ crash - Changed - Renamed function `unparseAnnotation()` into `unparseNode()` + - Renamed `EdgeCaseError` into `EdgeCaseError` ## [0.5.9] - 2024-09-29 diff --git a/pydoclint/utils/arg.py b/pydoclint/utils/arg.py index 02ca84a..752ae57 100644 --- a/pydoclint/utils/arg.py +++ b/pydoclint/utils/arg.py @@ -3,8 +3,8 @@ from docstring_parser.common import DocstringAttr, DocstringParam +from pydoclint.utils.edge_case_error import EdgeCaseError from pydoclint.utils.generic import stripQuotes -from pydoclint.utils.internal_error import InternalError from pydoclint.utils.unparser_custom import unparseName @@ -212,7 +212,7 @@ def fromAstAssign(cls, astAssign: ast.Assign) -> 'ArgList': if isinstance(target, ast.Tuple): # such as `a, b = c, d = 1, 2` for j, item in enumerate(target.elts): if not isinstance(item, ast.Name): - raise InternalError( + raise EdgeCaseError( f'astAssign.targets[{i}].elts[{j}] is of' f' type {type(item)} instead of ast.Name' ) @@ -223,7 +223,7 @@ def fromAstAssign(cls, astAssign: ast.Assign) -> 'ArgList': elif isinstance(target, ast.Attribute): # e.g., uvw.xyz = 1 infoList.append(Arg(name=unparseName(target), typeHint='')) else: - raise InternalError( + raise EdgeCaseError( f'astAssign.targets[{i}] is of type {type(target)}' ) @@ -292,7 +292,7 @@ def findArgsWithDifferentTypeHints(self, other: 'ArgList') -> List[Arg]: """Find args with unmatched type hints.""" if not self.equals(other, checkTypeHint=False, orderMatters=False): msg = 'These 2 arg lists do not have the same arg names' - raise InternalError(msg) + raise EdgeCaseError(msg) result: List[Arg] = [] for selfArg in self.infoList: diff --git a/pydoclint/utils/doc.py b/pydoclint/utils/doc.py index 035de65..3b82085 100644 --- a/pydoclint/utils/doc.py +++ b/pydoclint/utils/doc.py @@ -11,7 +11,7 @@ from docstring_parser.rest import parse as parseSphinx from pydoclint.utils.arg import ArgList -from pydoclint.utils.internal_error import InternalError +from pydoclint.utils.edge_case_error import EdgeCaseError from pydoclint.utils.return_arg import ReturnArg from pydoclint.utils.yield_arg import YieldArg @@ -141,7 +141,7 @@ def yieldSection(self) -> List[YieldArg]: def _raiseException(self) -> None: msg = f'Unknown style "{self.style}"; please contact the authors' - raise InternalError(msg) + raise EdgeCaseError(msg) @classmethod def _str(cls, something: Any) -> str: diff --git a/pydoclint/utils/edge_case_error.py b/pydoclint/utils/edge_case_error.py new file mode 100644 index 0000000..fcebc7a --- /dev/null +++ b/pydoclint/utils/edge_case_error.py @@ -0,0 +1,2 @@ +class EdgeCaseError(Exception): + """Errors from edge cases""" diff --git a/pydoclint/utils/internal_error.py b/pydoclint/utils/internal_error.py deleted file mode 100644 index 13b5f4d..0000000 --- a/pydoclint/utils/internal_error.py +++ /dev/null @@ -1,2 +0,0 @@ -class InternalError(Exception): - """Internal error for 'should not have happened' situations""" diff --git a/pydoclint/utils/return_anno.py b/pydoclint/utils/return_anno.py index e27ccd1..0c96288 100644 --- a/pydoclint/utils/return_anno.py +++ b/pydoclint/utils/return_anno.py @@ -2,8 +2,8 @@ import json from typing import List, Optional +from pydoclint.utils.edge_case_error import EdgeCaseError from pydoclint.utils.generic import stripQuotes -from pydoclint.utils.internal_error import InternalError from pydoclint.utils.unparser_custom import unparseName @@ -34,15 +34,15 @@ def decompose(self) -> List[str]: Raises ------ - InternalError + EdgeCaseError When the annotation string has strange values """ if self._isTuple(): # noqa: R506 if not self.annotation.endswith(']'): - raise InternalError('Return annotation not ending with `]`') + raise EdgeCaseError('Return annotation not ending with `]`') if len(self.annotation) < 7: - raise InternalError(f'Impossible annotation {self.annotation}') + raise EdgeCaseError(f'Impossible annotation {self.annotation}') if self.annotation.lower() == 'tuple[]': return [] @@ -59,7 +59,7 @@ def decompose(self) -> List[str]: elts: List = parsedBody0.value.elts return [unparseName(_) for _ in elts] - raise InternalError('decompose(): This should not have happened') + raise EdgeCaseError('decompose(): This should not have happened') else: return self.putAnnotationInList() diff --git a/pydoclint/utils/violation.py b/pydoclint/utils/violation.py index 18294e0..92207c9 100644 --- a/pydoclint/utils/violation.py +++ b/pydoclint/utils/violation.py @@ -2,7 +2,7 @@ from copy import deepcopy from typing import Tuple -from pydoclint.utils.internal_error import InternalError +from pydoclint.utils.edge_case_error import EdgeCaseError VIOLATION_CODES = types.MappingProxyType({ 1: 'Potential formatting errors in docstring. Error message:', @@ -76,7 +76,7 @@ def __init__( msgPostfix: str = '', ) -> None: if code not in VIOLATION_CODES: - raise InternalError('Invalid violation code') + raise EdgeCaseError('Invalid violation code') self.line = line self.code = code diff --git a/pydoclint/utils/visitor_helper.py b/pydoclint/utils/visitor_helper.py index f9660f8..2b193a9 100644 --- a/pydoclint/utils/visitor_helper.py +++ b/pydoclint/utils/visitor_helper.py @@ -5,13 +5,13 @@ from pydoclint.utils.arg import Arg, ArgList from pydoclint.utils.doc import Doc +from pydoclint.utils.edge_case_error import EdgeCaseError from pydoclint.utils.generic import ( appendArgsToCheckToV105, getDocstring, specialEqual, stripQuotes, ) -from pydoclint.utils.internal_error import InternalError from pydoclint.utils.return_anno import ReturnAnnotation from pydoclint.utils.return_arg import ReturnArg from pydoclint.utils.special_methods import checkIsPropertyMethod @@ -147,7 +147,7 @@ def extractClassAttributesFromNode( Raises ------ - InternalError + EdgeCaseError When the length of item.targets is 0 """ if 'body' not in node.__dict__ or len(node.body) == 0: @@ -159,7 +159,7 @@ def extractClassAttributesFromNode( atl.append(Arg.fromAstAnnAssign(itm)) elif isinstance(itm, ast.Assign): # no type hints if not isinstance(itm.targets, list) or len(itm.targets) == 0: - raise InternalError( + raise EdgeCaseError( '`item.targets` needs to be a list of length > 0.' f' Instead, it is {itm.targets}' ) diff --git a/pydoclint/visitor.py b/pydoclint/visitor.py index 24bfdbd..acdaedc 100644 --- a/pydoclint/visitor.py +++ b/pydoclint/visitor.py @@ -4,6 +4,7 @@ from pydoclint.utils.arg import Arg, ArgList from pydoclint.utils.astTypes import FuncOrAsyncFuncDef from pydoclint.utils.doc import Doc +from pydoclint.utils.edge_case_error import EdgeCaseError from pydoclint.utils.generic import ( collectFuncArgs, detectMethodType, @@ -11,7 +12,6 @@ generateFuncMsgPrefix, getDocstring, ) -from pydoclint.utils.internal_error import InternalError from pydoclint.utils.method_type import MethodType from pydoclint.utils.return_anno import ReturnAnnotation from pydoclint.utils.return_arg import ReturnArg @@ -244,7 +244,7 @@ def _checkClassDocstringAndConstructorDocstrings( # noqa: C901 'This should not have happened; please contact the authors' ' and share the full call stack.' ) - raise InternalError(msg) + raise EdgeCaseError(msg) className: str = parent_.name classLineNum: int = parent_.lineno diff --git a/setup.cfg b/setup.cfg index 9a1e34c..4d5d763 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = pydoclint -version = 0.5.9 +version = 0.5.10 description = A Python docstring linter that checks arguments, returns, yields, and raises sections long_description = file: README.md long_description_content_type = text/markdown