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 handling with union types in signatures #3300

Merged
merged 6 commits into from Sep 6, 2017

Conversation

Projects
None yet
3 participants
@JukkaL
Collaborator

JukkaL commented May 2, 2017

Previously None was not considered as more precise than
Optional[x], which was obviously incorrect. Fixed the
implementation of type precision checking to match the
description, now that proper subtype checking works.

Fixes the original example in #3295.

Fix overload handling with union types in signatures
Previously `None` was not considered as more precise than
`Optional[x]`, which was obviously incorrect. Fixed the
implementation of type precision checking to match the
description, how that proper subtype checking works.

Fixes the original example in #3295.
@gvanrossum

This comment has been minimized.

Show comment
Hide comment
@gvanrossum

gvanrossum May 2, 2017

Member

I had a similar testcase based on #3295 which still gives an error:

from typing import overload, Optional

@overload
def foo(x: None) -> None:
    pass
@overload
def foo(x: int) -> int:
    pass
def foo(*args):
    pass

def f(a: Optional[int]):
    reveal_type(foo(a))  # Line 13
    if isinstance(a, int):
        reveal_type(foo(a))
    else:
        reveal_type(foo(a))  # Error here

With --strict-optional, the output is unchanged from master:

__tmp__.py:13: error: Revealed type is 'Any'
__tmp__.py:15: error: Revealed type is 'builtins.int'
__tmp__.py:17: error: Revealed type is 'Any'
__tmp__.py:17: error: "foo" does not return a value
Member

gvanrossum commented May 2, 2017

I had a similar testcase based on #3295 which still gives an error:

from typing import overload, Optional

@overload
def foo(x: None) -> None:
    pass
@overload
def foo(x: int) -> int:
    pass
def foo(*args):
    pass

def f(a: Optional[int]):
    reveal_type(foo(a))  # Line 13
    if isinstance(a, int):
        reveal_type(foo(a))
    else:
        reveal_type(foo(a))  # Error here

With --strict-optional, the output is unchanged from master:

__tmp__.py:13: error: Revealed type is 'Any'
__tmp__.py:15: error: Revealed type is 'builtins.int'
__tmp__.py:17: error: Revealed type is 'Any'
__tmp__.py:17: error: "foo" does not return a value
@gvanrossum

This comment has been minimized.

Show comment
Hide comment
@gvanrossum

gvanrossum May 10, 2017

Member

@JukkaL This seems stalled waiting for action/response on your end.

Member

gvanrossum commented May 10, 2017

@JukkaL This seems stalled waiting for action/response on your end.

@gvanrossum

This comment has been minimized.

Show comment
Hide comment
@gvanrossum
Member

gvanrossum commented Jun 10, 2017

@JukkaL, ping?

@JukkaL

This comment has been minimized.

Show comment
Hide comment
@JukkaL

JukkaL Jun 28, 2017

Collaborator

This PR only addresses the first example in #3295. The more general issue requires a much more involved fix, and I think that it can be fixed in a separate PR.

Collaborator

JukkaL commented Jun 28, 2017

This PR only addresses the first example in #3295. The more general issue requires a much more involved fix, and I think that it can be fixed in a separate PR.

@ilevkivskyi

This is fine for me as a quick fix. A broader solution for #3295 can be in a separate PR

@JukkaL

This comment has been minimized.

Show comment
Hide comment
@JukkaL

JukkaL Jun 28, 2017

Collaborator

Don't merge yet -- I'll check this with Dropbox internal codebases first.

Collaborator

JukkaL commented Jun 28, 2017

Don't merge yet -- I'll check this with Dropbox internal codebases first.

@JukkaL

This comment has been minimized.

Show comment
Hide comment
@JukkaL

JukkaL Jul 5, 2017

Collaborator

This doesn't work quite right when run against Dropbox internal codebases. I won't merge this until I've resolved the issue.

Collaborator

JukkaL commented Jul 5, 2017

This doesn't work quite right when run against Dropbox internal codebases. I won't merge this until I've resolved the issue.

@JukkaL JukkaL merged commit a423d67 into master Sep 6, 2017

3 checks passed

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

@gvanrossum gvanrossum deleted the union-overloading branch Sep 29, 2017

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