Skip to content

Unintended consequences of eliminating promotions with isinstance? #6180

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

Closed
msullivan opened this issue Jan 11, 2019 · 5 comments
Closed

Unintended consequences of eliminating promotions with isinstance? #6180

msullivan opened this issue Jan 11, 2019 · 5 comments

Comments

@msullivan
Copy link
Collaborator

Previously, the following code:

def foo(x):
    # type: (unicode) -> None
    if isinstance(x, str):
        reveal_type(x)
    else:
        reveal_type(x)

would emit the expected types (str, unicode) in each branch
Post #6114, which removed the use of promotions when doing isinstance,
it only emits that the type is unicode and skips checking the first branch.

Is this bad? Should we be doing something else? Obviously str is not really a subtype of unicode, but there are a lot of places where things declared unicode can actually be str.

I think the intention with the first fix was to mostly to fix Union-related issues, so maybe we need a special case for non-unions? Argh.

Thoughts?

@msullivan
Copy link
Collaborator Author

And, this is a regression---albeit a false negative regression. It might be worth thinking about before the release (#6130)

@msullivan
Copy link
Collaborator Author

(Thoughts, @Michael0x2a ?)

@Michael0x2a
Copy link
Collaborator

Michael0x2a commented Jan 11, 2019

Honestly, at this stage, I think we should just revert the pull request I made and re-open #6060. I think it's pretty clear this has more ramifications then intended, and it doesn't seem like the original issue is really that glaring of an issue anyways.

We can then look into landing a more targeted and less disruptive fix after the release.

Really, the only reason why I went ahead and landed this was because it didn't seem to make a difference when I tried testing that fix internally -- but clearly, I messed up some part of that process.

@msullivan
Copy link
Collaborator Author

That sounds reasonable to me

Michael0x2a added a commit to Michael0x2a/mypy that referenced this issue Jan 11, 2019
This pull request reverts python#6114
and python#6142: see
python#6180 for rationale.

In short, the original fix ended up being more disruptive then
anticipated: it's modifying str and unicode semantics, and we should
put a little more thought into reasoning about that particular case
before moving ahead with any fix here.

This should also help unblock the upcoming 0.660 release.
Michael0x2a added a commit that referenced this issue Jan 11, 2019
This pull request reverts #6114
and #6142: see
#6180 for rationale.

In short, the original fix ended up being more disruptive then
anticipated: it's modifying str and unicode semantics, and we should
put a little more thought into reasoning about that particular case
before moving ahead with any fix here.

This should also help unblock the upcoming 0.660 release.
@ilevkivskyi
Copy link
Member

Do we need to keep both this and #6060 open? Maybe we can continue the discussion in #6060 and close this one?

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

No branches or pull requests

3 participants