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

Add pre-commit check for docstring param types #21398

Merged
merged 6 commits into from
Feb 8, 2022

Conversation

dstandish
Copy link
Contributor

Param types can now be inferred by sphinx from type annotations, so we no longer need them in docstrings.

This pre-commit check fails when type declarations are included in docstrings, and seems to do a reasonable job of not catching false positives.

@josh-fell your catches inspired me

@josh-fell
Copy link
Contributor

Hats off to @ashb for the original find!

@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Feb 7, 2022
@github-actions
Copy link

github-actions bot commented Feb 7, 2022

The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

Ehhhh. Regexp :)

I wish pydocstyle had a check for it but it does not.


def _check_file(file: Path) -> list:
content = file.read_text()
return re.findall(r' +\:type .+?\:', content)
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a check for rtype (return type) also?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently we can't do rtype at this time because not supported by sphinx

I'll try and link relevant pr comment later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see description here #21014 (comment)

Param types can now be inferred by sphinx from type annotations, so we no longer need them in docstrings.

This pre-commit check fails when type declarations are included in docstrings, and seems to do a reasonable job of not catching false positives.
@dstandish dstandish merged commit 0a3ff43 into apache:main Feb 8, 2022
@dstandish dstandish deleted the docstring-type-pre-commit branch February 8, 2022 23:07
@jedcunningham jedcunningham added the changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) label Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:dev-tools area:providers changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) full tests needed We need to run full set of tests for this PR to merge provider:google Google (including GCP) related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants