Skip to content

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

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.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions