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 type checking decorated method overrides #3918

Merged
merged 4 commits into from
Sep 13, 2017
Merged

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Sep 5, 2017

The fix turned out to be pretty complicated, as there were a bunch of
untested method overriding scenarios which weren't quite right. I
fixed any related issues that I encountered, though I'm not certain
whether some of the issues were hidden previously by other bugs. I
also added tests for some related, previously untested scenarios.

Fixes #1441.

The fix turned out to be pretty complicated, as there were a bunch of
untested method overriding scenarios which weren't quite right. I
fixed any related issues that I encountered, though I'm not certain
whether some of the issues were hidden previously by other bugs. I
also added tests for some related, previously untested scenarios.

Fixes #1441.
@JukkaL
Copy link
Collaborator Author

JukkaL commented Sep 5, 2017

This is ready for review, but don't merge this yet -- I have some outstanding fixes to internal Dropbox code bases that I want to land first before merging this.

@ilevkivskyi
Copy link
Member

It looks like you didn't update all tests, now all types are wrapped in quotes "...".

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Not a real review, just two random comments. Also this reminds me that there is an old related PR #3263, @kirbyfan64 are you still working on it?

mypy/checker.py Outdated
elif isinstance(original_type, AnyType):
context)
elif is_equivalent(original_type, typ):
# Assume invariance for a non-callable attribute here.
Copy link
Member

Choose a reason for hiding this comment

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

Wait, so does this PR also fix #3208?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No -- this only affects decorators that return a non-callable value (but @property is unaffected). This is a rare edge case. This also means that this will have only minor backward compatibility issues.

mypy/checker.py Outdated
elif is_equivalent(original_type, typ):
# Assume invariance for a non-callable attribute here.
#
# TODO: Allow covariance for read-only attributes?
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, protocols currently allow covariant overrides of read-only attributes (like @property).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@property is special and it can be overridden covariantly even outside protocols. I'll update the comment to mention that this doesn't affect @property.

Copy link
Member

Choose a reason for hiding this comment

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

What about writable properties?

@gvanrossum gvanrossum self-requested a review September 11, 2017 18:00
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

This looks ready to merge to me.

I should also mention that our internal codebase is now clear for this PR.

mypy/checker.py Outdated
elif is_equivalent(original_type, typ):
# Assume invariance for a non-callable attribute here.
#
# TODO: Allow covariance for read-only attributes?
Copy link
Member

Choose a reason for hiding this comment

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

What about writable properties?

@JukkaL JukkaL merged commit a771113 into master Sep 13, 2017
@JukkaL
Copy link
Collaborator Author

JukkaL commented Sep 13, 2017

What about writable properties?

These should be invariant, similar to regular attributes.

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.

Decorator on method in derived class
3 participants