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 untyped decorator check for class instances #5509

Merged
merged 9 commits into from Sep 21, 2018

Conversation

Projects
None yet
2 participants
@izquierdo
Contributor

izquierdo commented Aug 20, 2018

Running mypy --disallow-untyped-decorators when the decorator is a typed callable instance produces an error even though reveal_type shows the correct type.

Related to #4191 but I'll leave that one for a different PR.

@ilevkivskyi

Thanks for contributing! Here are few comments.

It looks like a proper fix for the issue would be to just add another branch for Overloaded type. I would do this in the same PR, but if you want a separate PR it is also OK.

method = typ.type.get_method('__call__')
if method and method.type:
return not is_typed_callable(method.type)
return True

This comment has been minimized.

@ilevkivskyi

ilevkivskyi Aug 20, 2018

Collaborator

If an Instance doesn't have a __call__ method this will return True, which will generate an additional spurious error. While I believe it shouldn't.

Could you please add a test case for this?

return typ.implicit
if isinstance(typ, CallableType):
return typ.implicit
if isinstance(typ, Instance):

This comment has been minimized.

@ilevkivskyi

ilevkivskyi Aug 20, 2018

Collaborator

if -> elif would be better here.

if isinstance(typ, Instance):
method = typ.type.get_method('__call__')
if method and method.type:
return not is_typed_callable(method.type)

This comment has been minimized.

@ilevkivskyi

ilevkivskyi Aug 20, 2018

Collaborator

This seems a bit inconsistent with the above. I would either use typ.implicit in both branches, or is_typed_callable in both branches.

@UntypedDecorator() # E: Untyped decorator makes function "f" untyped
@TypedDecorator()
def f() -> None: pass

This comment has been minimized.

@ilevkivskyi

ilevkivskyi Aug 20, 2018

Collaborator

Could you please add four separate checks that would check only first decorator, only second decorator, and both of them in different order. Each check should also have a reveal_type for the function so that it is clear the behaviour is correct.

@izquierdo

This comment has been minimized.

Contributor

izquierdo commented Aug 20, 2018

Thank you for the review. Updated with requested fixes + fix for the Overloaded type.

@ilevkivskyi

Sorry for a delay with review, this looks good now!

@ilevkivskyi ilevkivskyi merged commit 5afea77 into python:master Sep 21, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@izquierdo izquierdo deleted the izquierdo:untyped-decorators branch Sep 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment