Skip to content

Funny behaviour with Union[Decimal, int] #1442

@admirabilis

Description

@admirabilis

Considering the following program:

from decimal import Decimal
from typing import Union

def foo(bar: Union[Decimal, int]):
    print(Decimal(1) + bar)
    print(bar + Decimal(1))

Why does mypy complain in the second print()?

$ mypy foo.py
foo.py: note: In function "foo":
foo.py:6: error: Unsupported operand types for + ("Union[Decimal, int]" and "Decimal")

I'm using mypy 0.3.1 on Python 3.5.1, Ubuntu 16.04.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions