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

Union of a class with Any base and None is sometimes None #2712

Closed
JukkaL opened this issue Jan 19, 2017 · 1 comment · Fixed by #2718
Closed

Union of a class with Any base and None is sometimes None #2712

JukkaL opened this issue Jan 19, 2017 · 1 comment · Fixed by #2718

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jan 19, 2017

Without --strict-optional, the second reveal_type produces an incorrect result:

from typing import Any, Union, TypeVar

class C(Any):
    pass

T = TypeVar('T')
S = TypeVar('S')

def f(x: T, y: S) -> Union[T, S]:
    pass

reveal_type(f(C(), None))  # t.C
reveal_type(f(None, C()))  # builtins.None   <--- wrong

With --strict-optional, both of them are wrong:

...   # as above

reveal_type(f(C(), None))  # builtins.None   <--- wrong
reveal_type(f(None, C()))  # builtins.None   <--- wrong

This seems to cause problems in real-world code together with python/typeshed@6008b9d, so this is high priority.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jan 19, 2017

This looks very similar to the issue fixed by #2197. Maybe I'll just finish up that PR.

JukkaL added a commit that referenced this issue Jan 19, 2017
In particular, this helps with classes that have Any base classes.

This is enough to fix #2712. This is almost a subset of #2714
and should land before that, as this should cause less disruption.
gvanrossum pushed a commit that referenced this issue Jan 20, 2017
In particular, this helps with classes that have Any base classes.

This is enough to fix #2712. This is almost a subset of #2714
and should land before that, as this should cause less disruption.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant