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

[pydoclint] Implement docstring-missing-exception and docstring-extraneous-exception (DOC501, DOC502) #11471

Merged
merged 25 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
44c9adf
implement DAR401 and DAR402
augustelalande May 19, 2024
099b8b5
support numpy style
augustelalande May 19, 2024
d61c659
guess style if unspecified
augustelalande May 19, 2024
a3c8a97
clippy
augustelalande May 19, 2024
7a9ea53
fix docs
augustelalande May 19, 2024
8201569
bug
augustelalande May 19, 2024
228298d
share section_contexts
augustelalande May 19, 2024
5230744
clippy
augustelalande May 19, 2024
ebd102b
exclude classes
augustelalande May 19, 2024
cdb1604
order was intentional
augustelalande May 19, 2024
7a3c637
ignore variable exceptions for now
augustelalande May 19, 2024
596bf41
ignore variable exceptions
augustelalande May 20, 2024
3413e59
handle exception calls, i.e., Exception()
augustelalande May 20, 2024
4688d06
recode to pydoclint
augustelalande Jul 18, 2024
ebe2421
Merge branch 'main' into darglint
augustelalande Jul 18, 2024
269d3b6
add license
augustelalande Jul 18, 2024
1f62e07
return section_context directly
augustelalande Jul 19, 2024
c9bff03
document section styles
augustelalande Jul 19, 2024
b9da62d
clippy
augustelalande Jul 19, 2024
1705b53
document
augustelalande Jul 19, 2024
cb5e037
allow different variations of the qualified name in the docstring
augustelalande Jul 19, 2024
aae1027
add more tests for attribute exceptions
augustelalande Jul 19, 2024
585db73
clippy
augustelalande Jul 19, 2024
0434606
Update crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs
augustelalande Jul 19, 2024
9a6edd4
Add some docs; tweak diagnostic message; return None for no-Raises
charliermarsh Jul 20, 2024
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
25 changes: 25 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -1371,3 +1371,28 @@ are:
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

- pydoclint, licensed as follows:
"""
MIT License

Copyright (c) 2023 jsh9

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
192 changes: 192 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pydoclint/DOC501_google.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import something
from somewhere import AnotherError


class FasterThanLightError(Exception):
...


_some_error = Exception


# OK
def calculate_speed(distance: float, time: float) -> float:
"""Calculate speed as distance divided by time.

Args:
distance: Distance traveled.
time: Time spent traveling.

Returns:
Speed as distance divided by time.

Raises:
FasterThanLightError: If speed is greater than the speed of light.
"""
try:
return distance / time
except ZeroDivisionError as exc:
raise FasterThanLightError from exc


# DOC501
def calculate_speed(distance: float, time: float) -> float:
"""Calculate speed as distance divided by time.

Args:
distance: Distance traveled.
time: Time spent traveling.

Returns:
Speed as distance divided by time.
"""
try:
return distance / time
except ZeroDivisionError as exc:
raise FasterThanLightError from exc


# DOC501
def calculate_speed(distance: float, time: float) -> float:
"""Calculate speed as distance divided by time.

Args:
distance: Distance traveled.
time: Time spent traveling.

Returns:
Speed as distance divided by time.
"""
try:
return distance / time
except ZeroDivisionError as exc:
raise FasterThanLightError from exc
except:
raise ValueError


# DOC501
def calculate_speed(distance: float, time: float) -> float:
"""Calculate speed as distance divided by time.

Args:
distance: Distance traveled.
time: Time spent traveling.

Returns:
Speed as distance divided by time.
"""
try:
return distance / time
except ZeroDivisionError as exc:
print('oops')
raise exc


# DOC501
def calculate_speed(distance: float, time: float) -> float:
"""Calculate speed as distance divided by time.

Args:
distance: Distance traveled.
time: Time spent traveling.

Returns:
Speed as distance divided by time.
"""
try:
return distance / time
except (ZeroDivisionError, ValueError) as exc:
print('oops')
raise exc


# DOC501
def calculate_speed(distance: float, time: float) -> float:
"""Calculate speed as distance divided by time.

Args:
distance: Distance traveled.
time: Time spent traveling.

Returns:
Speed as distance divided by time.
"""
raise AnotherError


# DOC501
def calculate_speed(distance: float, time: float) -> float:
"""Calculate speed as distance divided by time.

Args:
distance: Distance traveled.
time: Time spent traveling.

Returns:
Speed as distance divided by time.
"""
raise AnotherError()


# DOC501
def foo(bar: int):
"""Foo.

Args:
bar: Bar.
"""
raise something.SomeError


# DOC501, but can't resolve the error
def calculate_speed(distance: float, time: float) -> float:
"""Calculate speed as distance divided by time.

Args:
distance: Distance traveled.
time: Time spent traveling.

Returns:
Speed as distance divided by time.
"""
raise _some_error


# OK
def calculate_speed(distance: float, time: float) -> float:
try:
return distance / time
except ZeroDivisionError as exc:
raise FasterThanLightError from exc


# OK
def calculate_speed(distance: float, time: float) -> float:
raise NotImplementedError


# OK
def foo(bar: int):
"""Foo.

Args:
bar: Bar.

Raises:
SomeError: Wow.
"""
raise something.SomeError


# OK
def foo(bar: int):
"""Foo.

Args:
bar: Bar.

Raises:
something.SomeError: Wow.
"""
raise something.SomeError
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
class FasterThanLightError(Exception):
...


# OK
def calculate_speed(distance: float, time: float) -> float:
"""
Calculate speed as distance divided by time.

Parameters
----------
distance : float
Distance traveled.
time : float
Time spent traveling.

Returns
-------
float
Speed as distance divided by time.

Raises
------
FasterThanLightError
If speed is greater than the speed of light.
"""
try:
return distance / time
except ZeroDivisionError as exc:
raise FasterThanLightError from exc


# DOC501
def calculate_speed(distance: float, time: float) -> float:
"""
Calculate speed as distance divided by time.

Parameters
----------
distance : float
Distance traveled.
time : float
Time spent traveling.

Returns
-------
float
Speed as distance divided by time.
"""
try:
return distance / time
except ZeroDivisionError as exc:
raise FasterThanLightError from exc


# DOC501
def calculate_speed(distance: float, time: float) -> float:
"""
Calculate speed as distance divided by time.

Parameters
----------
distance : float
Distance traveled.
time : float
Time spent traveling.

Returns
-------
float
Speed as distance divided by time.
"""
try:
return distance / time
except ZeroDivisionError as exc:
raise FasterThanLightError from exc
except:
raise ValueError
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
class FasterThanLightError(Exception):
...


# DOC502
def calculate_speed(distance: float, time: float) -> float:
"""Calculate speed as distance divided by time.

Args:
distance: Distance traveled.
time: Time spent traveling.

Returns:
Speed as distance divided by time.

Raises:
FasterThanLightError: If speed is greater than the speed of light.
"""
return distance / time


# DOC502
def calculate_speed(distance: float, time: float) -> float:
"""Calculate speed as distance divided by time.

Args:
distance: Distance traveled.
time: Time spent traveling.

Returns:
Speed as distance divided by time.

Raises:
FasterThanLightError: If speed is greater than the speed of light.
DivisionByZero: Divide by zero.
"""
return distance / time


# DOC502
def calculate_speed(distance: float, time: float) -> float:
"""Calculate speed as distance divided by time.

Args:
distance: Distance traveled.
time: Time spent traveling.

Returns:
Speed as distance divided by time.

Raises:
FasterThanLightError: If speed is greater than the speed of light.
DivisionByZero: Divide by zero.
"""
try:
return distance / time
except ZeroDivisionError as exc:
raise FasterThanLightError from exc
Loading
Loading