From 44ad2eeae9293a1e5084cbcb25ce6c364074f5e5 Mon Sep 17 00:00:00 2001 From: jsh9 <25124332+jsh9@users.noreply.github.com> Date: Sun, 15 Dec 2024 15:31:30 -0500 Subject: [PATCH] Fix violations in return_anno.py --- pydoclint/utils/return_anno.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pydoclint/utils/return_anno.py b/pydoclint/utils/return_anno.py index 0c96288..603c8e9 100644 --- a/pydoclint/utils/return_anno.py +++ b/pydoclint/utils/return_anno.py @@ -38,6 +38,8 @@ def decompose(self) -> List[str]: When the annotation string has strange values """ if self._isTuple(): # noqa: R506 + assert self.annotation is not None # to help mypy understand type + if not self.annotation.endswith(']'): raise EdgeCaseError('Return annotation not ending with `]`') @@ -49,15 +51,16 @@ def decompose(self) -> List[str]: insideTuple: str = self.annotation[6:-1] if insideTuple.endswith('...'): # like this: Tuple[int, ...] - return [self.annotation] # b/c we don't know the tuple's length + # because we don't know the tuple's length + return [self.annotation] - parsedBody0: ast.Expr = ast.parse(insideTuple).body[0] + parsedBody0: ast.Expr = ast.parse(insideTuple).body[0] # type:ignore[assignment] if isinstance(parsedBody0.value, ast.Name): # like this: Tuple[int] return [insideTuple] if isinstance(parsedBody0.value, ast.Tuple): # like Tuple[int, str] - elts: List = parsedBody0.value.elts - return [unparseName(_) for _ in elts] + elts: List[ast.expr] = parsedBody0.value.elts + return [unparseName(_) for _ in elts] # type:ignore[misc] raise EdgeCaseError('decompose(): This should not have happened') else: @@ -65,7 +68,8 @@ def decompose(self) -> List[str]: def _isTuple(self) -> bool: try: - annoHead = ast.parse(self.annotation).body[0].value.value.id + assert self.annotation is not None # to help mypy understand type + annoHead = ast.parse(self.annotation).body[0].value.value.id # type:ignore[attr-defined] return annoHead in {'tuple', 'Tuple'} except Exception: return False