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

fix: get name of a raised exception when bound in except #184

Merged
merged 3 commits into from
Dec 14, 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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## [0.5.11] - 2024-12-14

- Fixed

- Fixed a bug where pydoclint uses variable names instead of the exception
itself (https://github.com/jsh9/pydoclint/issues/175)

- Full diff
- https://github.com/jsh9/pydoclint/compare/0.5.11...0.5.10

## [0.5.10] - 2024-12-07

- Changed
Expand All @@ -9,9 +19,13 @@
- Fixed a bug where assigning a value to an attribute caused pydoclint to
crash
- Changed

- Renamed function `unparseAnnotation()` into `unparseNode()`
- Renamed `EdgeCaseError` into `EdgeCaseError`

- Full diff
- https://github.com/jsh9/pydoclint/compare/0.5.9...0.5.10

## [0.5.9] - 2024-09-29

- Fixed
Expand Down
15 changes: 15 additions & 0 deletions pydoclint/utils/return_yield_raise.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ def _getRaisedExceptions(
):
# case: looks like m.n.exception()
yield getFullAttributeName(child.exc.func)
elif (
currentParentExceptHandler
and currentParentExceptHandler.name
and subnode.id == currentParentExceptHandler.name
):
# case: "except <> as e; raise e" -> we must yield the
# stuff in <>
#
# Note: if subnode.id != currentParentExceptHandler.name,
# the user is raising something not bound by
# this exception handler (meaning we should fall
# through to yielding the subnode.id)
yield from _extractExceptionsFromExcept(
currentParentExceptHandler
)
else:
yield subnode.id

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.10
version = 0.5.11
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
11 changes: 11 additions & 0 deletions tests/utils/test_returns_yields_raise.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,15 @@ def func15():
x = 1
except other.Exception:
raise

def func16():
# ensure that "as e" doesn't mess up getting the name of an exception.
try:
3 + 3
except IOError as e:
raise e
except (KeyError, IndexError) as e:
raise e
"""


Expand All @@ -466,6 +475,7 @@ def testHasRaiseStatements() -> None:
(117, 0, 'func13'): True,
(126, 0, 'func14'): True,
(135, 0, 'func15'): True,
(141, 0, 'func16'): True,
}

assert result == expected
Expand Down Expand Up @@ -503,6 +513,7 @@ def testWhichRaiseStatements() -> None:
'm.n.ValueError',
],
(135, 0, 'func15'): ['other.Exception'],
(141, 0, 'func16'): ['IOError', 'IndexError', 'KeyError'],
}

assert result == expected
Loading