Skip to content

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

Closed

Description

@JukkaL

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.

Activity

  1. self-assigned this
    on Jan 19, 2017
  2. JukkaL commented on Jan 19, 2017

    @JukkaL
    CollaboratorAuthor

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

  3. added a commit that references this issue on Jan 19, 2017
    f43fd8f
  4. added a commit that references this issue on Jan 20, 2017
    9496d6f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions