Skip to content

[pydoclint] Teach rules to understand reraised exceptions as being explicitly raised#12639

Merged
AlexWaygood merged 1 commit intomainfrom
alex/reraise-docstring
Aug 2, 2024
Merged

[pydoclint] Teach rules to understand reraised exceptions as being explicitly raised#12639
AlexWaygood merged 1 commit intomainfrom
alex/reraise-docstring

Conversation

@AlexWaygood
Copy link
Copy Markdown
Member

@AlexWaygood AlexWaygood commented Aug 2, 2024

Summary

Fixes #12630.

DOC501 and DOC502 now understand functions with constructs like this to be explicitly raising TypeError (which should be documented in a function's docstring):

try:
    foo():
except TypeError:
    ...
    raise

I made an exception for Exception and BaseException, however. Constructs like this are reasonably common, and I don't think anybody would say that it's worth putting in the docstring that it raises "some kind of generic exception":

try:
    foo()
except BaseException:
    do_some_logging()
    raise

Test Plan

cargo test -p ruff_linter --lib

@AlexWaygood AlexWaygood added rule Implementing or modifying a lint rule docstring Related to docstring linting or formatting labels Aug 2, 2024
Comment on lines -574 to -584
fn extract_raised_exception<'a>(
semantic: &SemanticModel<'a>,
exc: &'a Expr,
) -> Option<QualifiedName<'a>> {
if let Some(qualified_name) = semantic.resolve_qualified_name(exc) {
return Some(qualified_name);
}
if let Expr::Call(ast::ExprCall { func, .. }) = exc {
return extract_raised_exception(semantic, func.as_ref());
}
None
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I got rid of this helper by using map_callable() before passing the node to resolve_qualified_name in visit_stmt

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 2, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+109 -0 violations, +0 -0 fixes in 4 projects; 50 projects unchanged)

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

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

+ airflow/datasets/__init__.py:112:17: DOC501 Raised exception `ValueError` missing from docstring
+ airflow/jobs/backfill_job_runner.py:1034:13: DOC501 Raised exception `OperationalError` missing from docstring
+ airflow/jobs/backfill_job_runner.py:713:37: DOC501 Raised exception `OperationalError` missing from docstring
+ airflow/jobs/scheduler_job_runner.py:1277:21: DOC501 Raised exception `OperationalError` missing from docstring
+ airflow/jobs/scheduler_job_runner.py:1917:21: DOC501 Raised exception `OperationalError` missing from docstring
+ airflow/jobs/triggerer_job_runner.py:639:13: DOC501 Raised exception `CancelledError` missing from docstring
+ airflow/models/connection.py:416:13: DOC501 Raised exception `ImportError` missing from docstring
+ airflow/models/dagbag.py:529:13: DOC501 Raised exception `AirflowClusterPolicySkipDag` missing from docstring
+ airflow/models/dagbag.py:529:13: DOC501 Raised exception `AirflowClusterPolicyViolation` missing from docstring
+ airflow/models/dagbag.py:563:13: DOC501 Raised exception `AirflowDagCycleException` missing from docstring
+ airflow/models/dagbag.py:563:13: DOC501 Raised exception `AirflowDagDuplicatedIdException` missing from docstring
+ airflow/models/dagbag.py:695:17: DOC501 Raised exception `OperationalError` missing from docstring
+ airflow/models/dagbag.py:726:21: DOC501 Raised exception `OperationalError` missing from docstring
+ airflow/models/taskinstance.py:286:17: DOC501 Raised exception `TaskDeferred` missing from docstring
+ airflow/models/taskinstance.py:315:13: DOC501 Raised exception `AirflowFailException` missing from docstring
+ airflow/models/taskinstance.py:315:13: DOC501 Raised exception `AirflowSensorTimeout` missing from docstring
+ airflow/models/taskinstance.py:328:17: DOC501 Raised exception `AirflowException` missing from docstring
+ airflow/models/taskinstance.py:328:17: DOC501 Raised exception `AirflowTaskTerminated` missing from docstring
+ airflow/models/taskinstance.py:328:17: DOC501 Raised exception `AirflowTaskTimeout` missing from docstring
+ airflow/models/taskinstance.py:765:13: DOC501 Raised exception `AirflowTaskTimeout` missing from docstring
+ airflow/models/xcom.py:696:13: DOC501 Raised exception `TypeError` missing from docstring
+ airflow/models/xcom.py:696:13: DOC501 Raised exception `ValueError` missing from docstring
+ airflow/providers/amazon/aws/auth_manager/cli/idc_commands.py:145:13: DOC501 Raised exception `ClientError` missing from docstring
+ airflow/providers/amazon/aws/executors/batch/batch_executor.py:149:13: DOC501 Raised exception `AirflowException` missing from docstring
+ airflow/providers/amazon/aws/executors/batch/batch_executor.py:282:17: DOC501 Raised exception `NoCredentialsError` missing from docstring
+ airflow/providers/amazon/aws/executors/batch/batch_executor.py:287:21: DOC501 Raised exception `ClientError` missing from docstring
+ airflow/providers/amazon/aws/executors/ecs/ecs_executor.py:130:13: DOC501 Raised exception `AirflowException` missing from docstring
+ airflow/providers/amazon/aws/executors/ecs/ecs_executor.py:359:17: DOC501 Raised exception `NoCredentialsError` missing from docstring
+ airflow/providers/amazon/aws/executors/ecs/ecs_executor.py:364:21: DOC501 Raised exception `ClientError` missing from docstring
+ airflow/providers/amazon/aws/hooks/athena.py:327:13: DOC501 Raised exception `KeyError` missing from docstring
+ airflow/providers/amazon/aws/hooks/batch_client.py:408:21: DOC501 Raised exception `ClientError` missing from docstring
+ airflow/providers/amazon/aws/hooks/eks.py:396:13: DOC501 Raised exception `ClientError` missing from docstring
+ airflow/providers/amazon/aws/hooks/eks.py:422:13: DOC501 Raised exception `ClientError` missing from docstring
+ airflow/providers/amazon/aws/hooks/eks.py:446:13: DOC501 Raised exception `ClientError` missing from docstring
+ airflow/providers/amazon/aws/hooks/emr.py:191:21: DOC501 Raised exception `AirflowException` missing from docstring
+ airflow/providers/amazon/aws/hooks/glue.py:262:21: DOC501 Raised exception `ClientError` missing from docstring
+ airflow/providers/amazon/aws/hooks/sagemaker.py:1056:13: DOC501 Raised exception `ClientError` missing from docstring
+ airflow/providers/amazon/aws/hooks/sagemaker.py:1137:13: DOC501 Raised exception `ClientError` missing from docstring
+ airflow/providers/amazon/aws/hooks/sagemaker.py:1209:25: DOC501 Raised exception `ClientError` missing from docstring
+ airflow/providers/amazon/aws/hooks/sagemaker.py:1260:17: DOC501 Raised exception `ClientError` missing from docstring
+ airflow/providers/amazon/aws/operators/datasync.py:358:13: DOC501 Raised exception `AirflowException` missing from docstring
+ airflow/providers/amazon/aws/operators/datasync.py:358:13: DOC501 Raised exception `AirflowTaskTimeout` missing from docstring
... 50 additional changes omitted for project

apache/superset (+13 -0 violations, +0 -0 fixes)

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

+ superset/commands/database/update.py:205:17: DOC501 Raised exception `DatabaseConnectionFailedError` missing from docstring
+ superset/commands/dataset/importers/v1/utils.py:99:13: DOC501 Raised exception `error` missing from docstring
+ superset/commands/importers/v1/utils.py:78:9: DOC501 Raised exception `ValidationError` missing from docstring
+ superset/commands/sql_lab/execute.py:124:13: DOC501 Raised exception `SupersetErrorException` missing from docstring
+ superset/commands/sql_lab/execute.py:124:13: DOC501 Raised exception `SupersetErrorsException` missing from docstring
+ superset/common/query_object.py:279:17: DOC501 Raised exception `QueryObjectValidationError` missing from docstring
+ superset/db_engine_specs/base.py:2003:17: DOC501 Raised exception `JSONDecodeError` missing from docstring
+ superset/db_engine_specs/base.py:2024:13: DOC501 Raised exception `JSONDecodeError` missing from docstring
+ superset/db_engine_specs/drill.py:146:13: DOC501 Raised exception `RuntimeError` missing from docstring
+ superset/models/helpers.py:321:13: DOC501 Raised exception `MultipleResultsFound` missing from docstring
... 3 additional changes omitted for project

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

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

+ src/bokeh/core/has_props.py:661:21: DOC501 Raised exception `UnsetValueError` missing from docstring
+ src/bokeh/document/document.py:384:17: DOC501 Raised exception `UnknownReferenceError` missing from docstring

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

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

+ corporate/views/remote_billing_page.py:209:9: DOC501 Raised exception `JsonableError` missing from docstring
+ zerver/forms.py:425:17: DOC501 Raised exception `RateLimitedError` missing from docstring

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
DOC501 109 109 0 0 0

@AlexWaygood AlexWaygood merged commit 3c1c319 into main Aug 2, 2024
@AlexWaygood AlexWaygood deleted the alex/reraise-docstring branch August 2, 2024 21:47
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.

[pydoclint] DOC502 should detect re-raised exceptions

2 participants