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

Fix overload resolution for metaclass #3511

Merged
merged 2 commits into from Jun 26, 2017

Conversation

elazarg
Copy link
Contributor

@elazarg elazarg commented Jun 8, 2017

Fix #3452.

reveal_type(f(e2)) # E: Revealed type is 'builtins.int'

[out]
main:6: error: An overloaded function outside a stub file must have an implementation
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this a bug?

Copy link
Member

Choose a reason for hiding this comment

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

No, there must be an implementation (or make this in a .pyi file in test).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But there is

Copy link
Member

Choose a reason for hiding this comment

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

This is not how overloads work. PEP 484:

In regular modules, a series of @overload-decorated definitions must be followed by exactly one non-@overload-decorated definition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, sorry. I will add one.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Looks good, just a few ideas for test cases.

class EM(type): pass
class E(metaclass=EM): pass

@overload
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice to have a few more test cases:

  • Test two overload variants which have two different metaclasses as argument types, and overloading based on metaclass.
  • Test calling the overloaded function with a str argument (results should be str).

@JukkaL JukkaL self-requested a review June 20, 2017 11:56
@JukkaL JukkaL self-assigned this Jun 20, 2017
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Looks good now. Thanks for fixing this!

@JukkaL JukkaL merged commit 53c6e58 into python:master Jun 26, 2017
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.

None yet

3 participants