Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename InternalError into EdgeCaseError #183

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,6 +10,7 @@
crash
- Changed
- Renamed function `unparseAnnotation()` into `unparseNode()`
- Renamed `EdgeCaseError` into `EdgeCaseError`

## [0.5.9] - 2024-09-29

Expand Down
8 changes: 4 additions & 4 deletions pydoclint/utils/arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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'
)
Expand All @@ -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)}'
)

Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pydoclint/utils/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions pydoclint/utils/edge_case_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class EdgeCaseError(Exception):
"""Errors from edge cases"""
2 changes: 0 additions & 2 deletions pydoclint/utils/internal_error.py

This file was deleted.

10 changes: 5 additions & 5 deletions pydoclint/utils/return_anno.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 []
Expand All @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions pydoclint/utils/violation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:',
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pydoclint/utils/visitor_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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}'
)
Expand Down
4 changes: 2 additions & 2 deletions pydoclint/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
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,
generateClassMsgPrefix,
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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading