Skip to content

Inconsistency in Union/promotion interactions #6168

Closed

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)

Activity

  1. ilevkivskyi commented on Jan 9, 2019

    @ilevkivskyi
    Member

    And probably the behavior ought to be to not simplify

    Yes, I think we should never use promotions in union simplification. Also this looks like something that may be easy to fix. We just need to use ignore_promotions=True in UnionType.make_simplified_union().

  2. ilevkivskyi commented on Jul 18, 2019

    @ilevkivskyi
    Member

    Added usability label because this can cause confusion, see #7241.

  3. hauntsaninja commented on Apr 26, 2023

    @hauntsaninja
    Collaborator

    These currently have the same type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions