Skip to content

Conditionally defined @propertys don't create union of types #3032

@Geo5

Description

@Geo5

Summary

For this snippet:

from typing import reveal_type
from random import random

class Baz:
    if random():
        def method(self) -> int:
            return 42

        @property
        def prop(self) -> int:
            return 42
    else:
        def method(self) -> str:
            return "hello"

        @property
        def prop(self) -> str:
            return "hello"

baz = Baz()
reveal_type(baz.prop) # revealed: int , expected: int | str
reveal_type(Baz.prop) # revealed: property, expected: ??
reveal_type(baz.method()) # revealed:  int | str ✔️ 

https://play.ty.dev/c50a02e5-56c0-486b-b599-6d8438678d18

I would expect a union type for baz.prop similar to baz.method().

I am not sure if the second reveal is also problematic.

Version

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions