FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-104050: Argument clinic: enable mypy's `--warn-return-any` setting by AlexWaygood · Pull Request #107405 · python/cpython · GitHub

/ cpython Public

gh-104050: Argument clinic: enable mypy's --warn-return-any setting - #107405

Merged
AlexWaygood merged 4 commits into
python:mainfrom
AlexWaygood:clinic-return-any
Jul 29, 2023
Merged

gh-104050: Argument clinic: enable mypy's --warn-return-any setting#107405
AlexWaygood merged 4 commits into
python:mainfrom
AlexWaygood:clinic-return-any

Conversation

AlexWaygood commented Jul 28, 2023
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

Mypy's --warn-return-any check flags when a function is declared to return a specific type, but mypy can't verify whether it's actually returning that type or not -- it can only infer a vague, unsafe Any type as the returned type. This can often lead to bugs slipping beneath the radar.

In the case of argument clinic, the check only flags a single function. But, turns out that it's a true positive! The function is incorrectly annotated at the moment -- the annotation says that it returns a FunctionType, but that's not true. The function creates a FunctionType instance fn, and then returns whatever calling fn returns returns. Therefore, the proper return annotation for this function is -> Any, not -> FunctionType.

Closes #104050!

Copy link
Copy Markdown
Contributor

Good sleuthing!

Comment thread Tools/clinic/clinic.py
*,
filename: str = '-'
) -> FunctionType:
) -> Any:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Should we add a comment as to why Any is the correct annotation here?

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You weren't going to make finally closing that issue easy, were you? ;)

Let me know if a5103be is too verbose...!

AlexWaygood Jul 28, 2023
edited
Loading

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hmm, actually, now that I look at it again, the comment feels like it duplicates the docstring a little bit... not sure if it's worth it? I'll defer to you on whether it's helpful or not!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sorry, you're right. The docstring should be enough!

AlexWaygood Jul 29, 2023
edited
Loading

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Okay -- removed the comment again and tweaked the docstring slightly! How's it look now?

erlend-aasland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yay!

AlexWaygood merged commit 87de2fb into python:main Jul 29, 2023
AlexWaygood deleted the clinic-return-any branch July 29, 2023 12:39

This comment was marked as off-topic.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add type annotations to clinic.py

3 participants


Back | FazBrowse Home | New Git URL