Skip to content

[stubgen] Add known return types to magic methods #13909

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

Merged
merged 1 commit into from
Oct 17, 2022

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Oct 16, 2022

This is based on the idea of https://github.com/JelleZijlstra/autotyping
Other magic methods can be added later.

CC @JelleZijlstra

@AlexWaygood
Copy link
Member

You could maybe also add __hash__? If it's an actual method (hasn't been set to None), it's always going to return an int:

>>> class Foo:
...     def __hash__(self):
...         return 'bar'
... 
...     
>>> hash(Foo())
Traceback (most recent call last):
  File "C:\Users\alexw\AppData\Local\Programs\Python\Python310\lib\idlelib\run.py", line 578, in runcode
    exec(code, self.locals)
  File "<pyshell#15>", line 1, in <module>
TypeError: __hash__ method should return an integer

@sobolevn
Copy link
Member Author

sobolevn commented Oct 16, 2022

Sure, in the next PRs!

Right now it will require:

  • __hash__: None vs def __hash__ tests
  • Further work, quick test (I added "__hash__": "int" to my source code) shows that it does not work out of the box, probably it has some extra logic

@sobolevn sobolevn requested a review from hauntsaninja October 17, 2022 07:47
@hauntsaninja
Copy link
Collaborator

Thanks, seems good!

@sobolevn sobolevn merged commit 045ea8c into python:master Oct 17, 2022
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.

3 participants