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

Conversation

augustelalande
Copy link
Contributor

@augustelalande augustelalande commented May 19, 2024

Summary

These are the first rules implemented as part of #458, but I plan to implement more.

Specifically, this implements docstring-missing-exception which checks for raised exceptions not documented in the docstring, and docstring-extraneous-exception which checks for exceptions in the docstring not present in the body.

Test Plan

Test fixtures added for both google and numpy style.

Copy link

codspeed-hq bot commented May 19, 2024

CodSpeed Performance Report

Merging #11471 will degrade performances by 97.48%

Comparing augustelalande:darglint (9a6edd4) with augustelalande:darglint (0434606)

Summary

❌ 3 regressions
✅ 30 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark augustelalande:darglint augustelalande:darglint Change
red_knot_check_file[cold] 346.4 µs 13,748.4 µs -97.48%
red_knot_check_file[incremental] 95 µs 422.7 µs -77.53%
red_knot_check_file[without_parse] 260.5 µs 6,345.5 µs -95.89%

Copy link
Contributor

github-actions bot commented May 19, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+2239 -0 violations, +0 -0 fixes in 3 projects; 47 projects unchanged)

apache/airflow (+1844 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

+ airflow/api/__init__.py:47:15: DAR401 Raised exception `AirflowException` missing from docstring
+ airflow/api/client/json_client.py:55:19: DAR401 Raised exception `OSError` missing from docstring
+ airflow/api/common/delete_dag.py:62:15: DAR401 Raised exception `AirflowException` missing from docstring
+ airflow/api/common/delete_dag.py:65:15: DAR401 Raised exception `DagNotFound` missing from docstring
+ airflow/api/common/experimental/__init__.py:37:15: DAR401 Raised exception `DagNotFound` missing from docstring
+ airflow/api/common/experimental/__init__.py:43:15: DAR401 Raised exception `DagNotFound` missing from docstring
+ airflow/api/common/experimental/__init__.py:46:15: DAR401 Raised exception `TaskNotFound` missing from docstring
+ airflow/api/common/experimental/__init__.py:55:15: DAR401 Raised exception `DagRunNotFound` missing from docstring
+ airflow/api/common/experimental/get_code.py:44:15: DAR401 Raised exception `AirflowException` missing from docstring
+ airflow/api/common/experimental/get_task_instance.py:44:15: DAR401 Raised exception `TaskInstanceNotFound` missing from docstring
+ airflow/api/common/experimental/get_task_instance.py:48:11: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/experimental/pool.py:40:15: DAR401 Raised exception `AirflowBadRequest` missing from docstring
+ airflow/api/common/experimental/pool.py:44:15: DAR401 Raised exception `PoolNotFound` missing from docstring
+ airflow/api/common/experimental/pool.py:61:15: DAR401 Raised exception `AirflowBadRequest` missing from docstring
+ airflow/api/common/experimental/pool.py:66:15: DAR401 Raised exception `AirflowBadRequest` missing from docstring
+ airflow/api/common/experimental/pool.py:71:15: DAR401 Raised exception `AirflowBadRequest` missing from docstring
+ airflow/api/common/experimental/pool.py:92:15: DAR401 Raised exception `AirflowBadRequest` missing from docstring
+ airflow/api/common/experimental/pool.py:95:15: DAR401 Raised exception `AirflowBadRequest` missing from docstring
+ airflow/api/common/experimental/pool.py:99:15: DAR401 Raised exception `PoolNotFound` missing from docstring
+ airflow/api/common/mark_tasks.py:123:15: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:126:15: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:130:15: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:133:15: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:138:15: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:300:15: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:333:15: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:400:19: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:403:19: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:406:15: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:453:19: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:456:19: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:460:15: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:544:19: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:547:19: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/mark_tasks.py:550:15: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/trigger_dag.py:123:15: DAR401 Raised exception `DagNotFound` missing from docstring
+ airflow/api/common/trigger_dag.py:56:15: DAR401 Raised exception `DagNotFound` missing from docstring
+ airflow/api/common/trigger_dag.py:61:15: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/trigger_dag.py:69:19: DAR401 Raised exception `ValueError` missing from docstring
+ airflow/api/common/trigger_dag.py:82:15: DAR401 Raised exception `DagRunAlreadyExists` missing from docstring
+ airflow/api_connexion/endpoints/config_endpoint.py:87:19: DAR401 Raised exception `NotFound` missing from docstring
... 1803 additional changes omitted for project

bokeh/bokeh (+189 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

+ src/bokeh/application/application.py:168:19: DAR401 Raised exception `RuntimeError` missing from docstring
+ src/bokeh/application/handlers/code_runner.py:94:19: DAR401 Raised exception `ValueError` missing from docstring
+ src/bokeh/application/handlers/directory.py:142:19: DAR401 Raised exception `ValueError` missing from docstring
+ src/bokeh/application/handlers/directory.py:153:19: DAR401 Raised exception `ValueError` missing from docstring
+ src/bokeh/client/connection.py:213:19: DAR401 Raised exception `RuntimeError` missing from docstring
+ src/bokeh/client/connection.py:215:19: DAR401 Raised exception `RuntimeError` missing from docstring
... 182 additional changes omitted for rule DAR401
+ src/bokeh/resources.py:165:1: DAR402 KeyError not explicitly raised.
+ src/bokeh/tile_providers.py:182:1: DAR402 ValueError not explicitly raised.
... 181 additional changes omitted for project

zulip/zulip (+206 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

+ analytics/lib/fixtures.py:57:15: DAR401 Raised exception `AssertionError` missing from docstring
+ analytics/lib/fixtures.py:59:15: DAR401 Raised exception `AssertionError` missing from docstring
+ confirmation/models.py:102:15: DAR401 Raised exception `ConfirmationKeyError` missing from docstring
+ confirmation/models.py:105:15: DAR401 Raised exception `ConfirmationKeyError` missing from docstring
+ confirmation/models.py:115:15: DAR401 Raised exception `ConfirmationKeyError` missing from docstring
+ confirmation/models.py:96:15: DAR401 Raised exception `ConfirmationKeyError` missing from docstring
+ corporate/lib/stripe.py:1160:19: DAR401 Raised exception `BillingError` missing from docstring
+ corporate/lib/stripe.py:1209:23: DAR401 Raised exception `StripeCardError` missing from docstring
+ corporate/views/remote_billing_page.py:203:15: DAR401 Raised exception `AssertionError` missing from docstring
+ corporate/views/remote_billing_page.py:218:15: DAR401 Raised exception `JsonableError` missing from docstring
... 196 additional changes omitted for project

Changes by rule (2 rules affected)

code total + violation - violation + fix - fix
DAR401 2237 2237 0 0 0
DAR402 2 2 0 0 0

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@charliermarsh charliermarsh added rule Implementing or modifying a lint rule docstring Related to docstring linting or formatting labels May 20, 2024
@cr1901
Copy link

cr1901 commented May 22, 2024

If this PR is accepted, will this preclude pydoclint (darglint successor but not really backwards-compat) support in the future? While pydoclint is the tool I personally use, it seems since yesterday, there are few thumbs-up asking about using pydoclint as a base instead.

@augustelalande
Copy link
Contributor Author

I'm not opposed to using pydocstyle instead, but I'll wait until I get a review from the ruff team to change anything.

Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this looks great. I'll make a few tweaks and merge today.

@augustelalande
Copy link
Contributor Author

@charliermarsh where do you stand on darglint vs pydoclint as mentioned above

@charliermarsh
Copy link
Member

Honestly, finding it hard to have a strong opinion on it... What do you think?

Absent other opinions, let's run with pydoclint given that it's actively developed? (And re-code these as DOC501 and DOC502?)

@augustelalande
Copy link
Contributor Author

Sounds reasonable to me

@augustelalande augustelalande changed the title [darglint] Implement docstring-missing-exception and docstring-extraneous-exception (DAR401, DAR402) [pydoclint] Implement docstring-missing-exception and docstring-extraneous-exception (DOC501, DOC502) Jul 18, 2024
@charliermarsh charliermarsh enabled auto-merge (squash) July 20, 2024 19:38
@charliermarsh charliermarsh added the preview Related to preview mode features label Jul 20, 2024
impl<'a> DocstringEntries<'a> {
/// Return the raised exceptions for the docstring, or `None` if the docstring does not contain
/// a `Raises` section.
fn from_sections(sections: &'a SectionContexts, style: SectionStyle) -> Option<Self> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to return None when there's no section, so we didn't have to unwrap the raised_exceptions_range. Feel free to revert in future PRs if that gets in the way, though I think something like that is useful to get rid of the unwrap.

@charliermarsh charliermarsh merged commit 4bc73dd into astral-sh:main Jul 20, 2024
18 checks passed
@T-256
Copy link
Contributor

T-256 commented Jul 20, 2024

Do we need to update title and description of #458 to keep tracking future implementations for this plugin?

@augustelalande augustelalande deleted the darglint branch July 21, 2024 03:30
@augustelalande
Copy link
Contributor Author

I'm thinking to open a new issue to track pydoclint and supersede #458

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docstring Related to docstring linting or formatting preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants