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

Fixes corner case for comparing nested overloads #9259

Merged
merged 2 commits into from
Aug 5, 2020
Merged

Fixes corner case for comparing nested overloads #9259

merged 2 commits into from
Aug 5, 2020

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Aug 4, 2020

We have this really nasty bug in returns with our @curry plugin:

So, this little fix solves the problem for us with very little effort.
In the ideal world, I would have to rewrite the whole thing to make the nested structures work.

Current problem is that we have a local state in matched_overloads and possible_invalid_overloads variables that is not syncronyzed with the nested calls.
I can also add a TODO note for later.

Refs dry-python/returns#410

We have this really nasty bug in `returns` with our `@curry` plugin:
- Closes #9147
- Closes #8978

So, this little fix solves the problem for us with very little effort.
In the ideal world, I would have to rewrite the whole thing to make the nested structures work.

Current problem is that we have a local state in `matched_overloads` and `possible_invalid_overloads` variables that is not syncronyzed with the nested calls.
I can also add a `TODO` note for later.
@sobolevn
Copy link
Member Author

sobolevn commented Aug 4, 2020

Testing that this solves our issue:

from returns.curry import curry
from returns.io import IO

@curry
def test(a: int, b: int, c: int) -> int:
    ...

reveal_type(test)  # works
reveal_type(IO(1).apply(IO(test)))  # fails

Without this fix:

» mypy ex.py
ex.py:8: note: Revealed type is 'Overload(def (a: builtins.int) -> Overload(def (b: builtins.int, c: builtins.int) -> builtins.int, def (b: builtins.int) -> def (c: builtins.int) -> builtins.int), def (a: builtins.int, b: builtins.int) -> def (c: builtins.int) -> builtins.int, def (a: builtins.int, b: builtins.int, c: builtins.int) -> builtins.int)'
ex.py:9: note: Revealed type is 'returns.io.IO[Overload(def (b: builtins.int, c: builtins.int) -> builtins.int, def (b: builtins.int) -> def (c: builtins.int) -> builtins.int)]'
ex.py:9: error: Argument 1 to "IO" has incompatible type overloaded function; expected overloaded function

With this fix:

» python -m mypy /Users/sobolev/Documents/github/returns/ex.py --config-file=/Users/sobolev/Documents/github/returns/setup.cfg
/Users/sobolev/Documents/github/returns/ex.py:8: note: Revealed type is 'Overload(def (a: builtins.int) -> Overload(def (b: builtins.int, c: builtins.int) -> builtins.int, def (b: builtins.int) -> def (c: builtins.int) -> builtins.int), def (a: builtins.int, b: builtins.int) -> def (c: builtins.int) -> builtins.int, def (a: builtins.int, b: builtins.int, c: builtins.int) -> builtins.int)'
/Users/sobolev/Documents/github/returns/ex.py:9: note: Revealed type is 'returns.io.IO[Overload(def (b: builtins.int, c: builtins.int) -> builtins.int, def (b: builtins.int) -> def (c: builtins.int) -> builtins.int)]'

It works! 🎉

@sobolevn
Copy link
Member Author

sobolevn commented Aug 4, 2020

This failure does not seem related:

----------------------------- Captured stdout call -----------------------------

mypy: Failed to import, skipping

----------------------------- Captured stderr call -----------------------------

Inconsistency detected by ld.so: dl-open.c: 231: dl_open_worker: Assertion `_dl_debug_initialize (0, args->nsid)->r_state == RT_CONSISTENT' failed!

@gvanrossum
Copy link
Member

Let me close and reopen the issue to see if re-running the tests fares better.

@gvanrossum gvanrossum closed this Aug 5, 2020
@gvanrossum gvanrossum reopened this Aug 5, 2020
@gvanrossum gvanrossum changed the title Fixes our very own case for comparing nested overloads Fixes corner case for comparing nested overloads Aug 5, 2020
mypy/subtypes.py Outdated
Comment on lines 404 to 405
# This was originally introduced as a fix / hack for:
# https://github.com/python/mypy/issues/9147
Copy link
Member

Choose a reason for hiding this comment

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

There is no need to add a comment in the source referring to the bug (people can find that information using git blame).

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@gvanrossum
Copy link
Member

LGTM. Would it be feasible to add a unit test?

@sobolevn
Copy link
Member Author

sobolevn commented Aug 5, 2020

@gvanrossum I don't know how to easily replicate this. Because creating a nested Overloaded is not possible without a plugin AFAIK.

I can write one if that's required. But, if you ask me I would probably leave this as-is.

@gvanrossum
Copy link
Member

Okay, that's fine then.

@gvanrossum gvanrossum merged commit b10d540 into python:master Aug 5, 2020
@sobolevn sobolevn deleted the patch-1 branch August 5, 2020 19:59
@sobolevn
Copy link
Member Author

sobolevn commented Aug 5, 2020

@gvanrossum thanks a lot! 👍

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