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

Don't require a returns section for NoReturn #57

Merged
merged 6 commits into from
Aug 15, 2023
Merged

Conversation

llucax
Copy link
Contributor

@llucax llucax commented Aug 10, 2023

When a function has a return type of NoReturn it means it will never return, so the documentation doesn't really need to specify a return.

The option --require-return-section-when-returning-none was renamed to --require-return-section-when-returning-nothing to highlight it is more generic now, as it will also require a returns section for NoReturn. The old option is kept as a deprecation error.

Fixes #55.

When a function has a return type of `NoReturn` it means it will never
return, so the documentation doesn't really need to specify a return.

The option `--require-return-section-when-returning-none` was renamed to
`--require-return-section-when-returning-nothing` to highlight it is
more generic now, as it will also require a returns section for
`NoReturn`. The old option is kept as a deprecation error.

Signed-off-by: Leandro Lucarella <[email protected]>
return returnAnnotation.startswith('NoReturn')


def _isNoReturn(node: ast.AST) -> bool:
Copy link
Owner

Choose a reason for hiding this comment

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

This function doesn't seem to be used anywhere?

Copy link
Owner

Choose a reason for hiding this comment

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

And comparing the implementation of this function and that of isReturnAnnotationNoReturn(), it seems that the implementation of this function is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @jsh9!

This function doesn't seem to be used anywhere?

Yeah, good catch. This is a leftover from a version that didn't work. I should (maybe?) remove it.

And comparing the implementation of this function and that of isReturnAnnotationNoReturn(), it seems that the implementation of this function is better?

It looks better but it didn't work for me. I'm not familiar with the ast stuff here, so not sure if there is a way to make it work, but when I tried it it seems like NoReturn is not a ast.Constant but a ast.Name IIRC., this is why I had to go with the string comparison. I think I could also just do returnAnnotation == 'NoReturn', the startwidth() was based on the generator stuff but in this case I think it should only match to NoReturn.

pydoclint/visitor.py Outdated Show resolved Hide resolved
@jsh9
Copy link
Owner

jsh9 commented Aug 12, 2023

Hi @llucax , thank you so much for finding this issue and submitting this PR!

The code changes generally look good, and I think the renaming from "none" and "nothing" is very appropriate!

I left a few comments above, basically some curious questions. Would you mind taking a look at them?

llucax and others added 2 commits August 14, 2023 11:08
This applies the suggestion made during the review.

Co-authored-by: jsh9 <[email protected]>
Also compare against `NoReturn` via `==` instead of using
`startswith()`, as we really want to match `NoReturn` literally.

Signed-off-by: Leandro Lucarella <[email protected]>
@llucax
Copy link
Contributor Author

llucax commented Aug 14, 2023

Hi @jsh9, I updated the PR with your suggestions and comments. Let me know if you think isReturnAnnotationNoReturn() can be improved.

@jsh9
Copy link
Owner

jsh9 commented Aug 15, 2023

Hi @llucax , I think isReturnAnnotationNoReturn() is good. Let me merge it now.

Thanks again for the contribution!

@jsh9 jsh9 merged commit 170da52 into jsh9:main Aug 15, 2023
@llucax llucax deleted the noreturn branch August 15, 2023 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support return type NoReturn
2 participants