Skip to content

Inconsistency in Union/promotion interactions #6168

@msullivan

Description

@msullivan

In the following test

from typing import Union

class A:
    x: Union[int, float]

def foo(x: Union[int, float], y: A) -> None:
    reveal_type(x)
    reveal_type(y.x)

we emit:

lol.py:8: error: Revealed type is 'Union[builtins.int, builtins.float]'
lol.py:9: error: Revealed type is 'builtins.float'

That is to say, class attributes have unions simplified using promotions while arguments (and locals) do not.

Probably they ought to have the same behavior?
(And probably the behavior ought to be to not simplify, especially because of #6114)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions