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

Improve Tuple/Sequence/Iterable overlapping #5315

Merged
merged 6 commits into from Jul 22, 2018

Conversation

Projects
None yet
4 participants
@ethanhs
Collaborator

ethanhs commented Jul 4, 2018

Fixes #4466

@ilevkivskyi hopefully this is similar to what you were expecting?

@ilevkivskyi ilevkivskyi self-requested a review Jul 4, 2018

@ilevkivskyi ilevkivskyi self-assigned this Jul 4, 2018

@Michael0x2a

Well, I'm not Ivan, but I'm also bored so here's a code review.

Apologies in advance if the review ended up being incoherent in places -- I'm sort of bouncing between different things atm.

Show outdated Hide outdated mypy/meet.py Outdated
Show outdated Hide outdated mypy/meet.py Outdated
Show outdated Hide outdated mypy/meet.py Outdated

@ilevkivskyi ilevkivskyi removed their assignment Jul 5, 2018

@ilevkivskyi ilevkivskyi removed their request for review Jul 5, 2018

@ilevkivskyi

I think I have few things to add here.

Show outdated Hide outdated mypy/meet.py Outdated
Show outdated Hide outdated mypy/meet.py Outdated
Show outdated Hide outdated mypy/meet.py Outdated
@ilevkivskyi

Sorry for a delay with this! Feel free to merge this after you consider one last comment.

@Michael0x2a could you please double-check this PR doesn't cause problems in internal codebases?

Show outdated Hide outdated mypy/meet.py Outdated
@Michael0x2a

This comment has been minimized.

Show comment
Hide comment
@Michael0x2a

Michael0x2a Jul 21, 2018

Collaborator

@ilevkivskyi -- sure! I have to go to a thing, but I can re-run these tests a little later tonight.

@ethanhs -- I'm not sure if your PR will run into this case or not, but I remember running into this edge case while working on my other PR yesterday. Could you try checking to see what your PR does on this test case?

from typing import *

# E.g. maybe this was imported from a non-typed module
Parent: Any

class Child(Parent):
    def some_method(self) -> int:
        if self is None:
            return None
        return 3

I believe the current behavior of mypy is to report no errors when running in strict-optional mode. If your PR complains about the "return None", you may have to swap out the two calls to is_subtype with is_proper_subtype or something.

(The actual code that I synthesized this from does self = super(Child, self).blah() before the if statement, so the above example is a little less stupid than it looks, if only marginally.)

Collaborator

Michael0x2a commented Jul 21, 2018

@ilevkivskyi -- sure! I have to go to a thing, but I can re-run these tests a little later tonight.

@ethanhs -- I'm not sure if your PR will run into this case or not, but I remember running into this edge case while working on my other PR yesterday. Could you try checking to see what your PR does on this test case?

from typing import *

# E.g. maybe this was imported from a non-typed module
Parent: Any

class Child(Parent):
    def some_method(self) -> int:
        if self is None:
            return None
        return 3

I believe the current behavior of mypy is to report no errors when running in strict-optional mode. If your PR complains about the "return None", you may have to swap out the two calls to is_subtype with is_proper_subtype or something.

(The actual code that I synthesized this from does self = super(Child, self).blah() before the if statement, so the above example is a little less stupid than it looks, if only marginally.)

@JelleZijlstra

This comment has been minimized.

Show comment
Hide comment
@JelleZijlstra

JelleZijlstra Jul 21, 2018

Collaborator

Maybe I'm missing something, but shouldn't that code sample produce an error under strict optional? It returns None but is declared to return int.

Collaborator

JelleZijlstra commented Jul 21, 2018

Maybe I'm missing something, but shouldn't that code sample produce an error under strict optional? It returns None but is declared to return int.

@ilevkivskyi

This comment has been minimized.

Show comment
Hide comment
@ilevkivskyi

ilevkivskyi Jul 21, 2018

Collaborator

@JelleZijlstra mypy infers the branch as unreachable.

Collaborator

ilevkivskyi commented Jul 21, 2018

@JelleZijlstra mypy infers the branch as unreachable.

ethanhs added some commits Jul 21, 2018

@ethanhs

This comment has been minimized.

Show comment
Hide comment
@ethanhs

ethanhs Jul 21, 2018

Collaborator

@Michael0x2a thanks! That was indeed an issue, and is_proper_subtype fixed it :)

I also reverted the unneeded changes as suggested by Ivan.

Collaborator

ethanhs commented Jul 21, 2018

@Michael0x2a thanks! That was indeed an issue, and is_proper_subtype fixed it :)

I also reverted the unneeded changes as suggested by Ivan.

@Michael0x2a Michael0x2a merged commit 3fb16a2 into python:master Jul 22, 2018

2 checks passed

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

@ethanhs ethanhs deleted the ethanhs:tuplesequence branch Jul 22, 2018

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