Skip to content

Handling @overload with a docstring declaration #368

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

arnav-jain1
Copy link
Contributor

@arnav-jain1 arnav-jain1 commented May 27, 2025

fixes #359. Added a check to make sure the body was not a docstring. Also added a test in the the third_party folder to show that the change is working. Let me know if anything needs to be changed.

@yangdanny97
Copy link
Contributor

yangdanny97 commented May 27, 2025

Thanks!

The third_party/conformance tests are pulled from the typing spec conformance test suite, and shouldn't be modified directly here: https://github.com/python/typing/tree/main/conformance

For this type of feature, could you please add an integration test here? https://github.com/facebook/pyrefly/blob/main/pyrefly/lib/test/overload.rs

Also, I think we should only allow docstrings for function bodies if there is an @overload decorator

For example, a program like this should still be invalid:

def foo() -> int:
    """hello"""

Copy link
Contributor

@yangdanny97 yangdanny97 left a comment

Choose a reason for hiding this comment

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

Back to you with comments, lmk if you have any questions. Thanks!

@arnav-jain1
Copy link
Contributor Author

Should be fixed. Added 3 test cases, first one is the basic one. Second one was to make sure that stuff after a docstring would still be typechecked properly and if the body of the function had more info, it wouldn't deem it a stub. The last one is for the case you mentioned of the nonoverloaded function with a docstring.

@arnav-jain1
Copy link
Contributor Author

My commits are a bit messy because I am a little new to this but the code should be right

@arnav-jain1 arnav-jain1 requested a review from yangdanny97 June 9, 2025 03:31
@arnav-jain1
Copy link
Contributor Author

Also if you have others that you want me to fix, let me know! I am a bit swamped right now but I can try and get to it soon.

@facebook-github-bot
Copy link
Contributor

@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

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.

Don't check return type for @overload and docstring
3 participants