Skip to content

Accessing property through a Union doesn't work #14439

@julian-klode

Description

@julian-klode

Bug Report

Accessing a property typed to the object we access , e.g. a property defining __get__(self, obj: B, ...) through a Union[A,B] complains that the argument to __get__ has union type, despite being defined in B.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.11&gist=e7d68cb2fa9867b0c21c66f7b33637e5

Expected Behavior

No errors

Actual Behavior

main.py:35: error: Argument 1 to "__get__" of "SingleValueProperty" has incompatible type "Union[A, B]"; expected "B"  [arg-type]
main.py:39: error: Argument 1 to "__get__" of "SingleValueProperty" has incompatible type "Union[A, B]"; expected "B"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

Your Environment

The mypy playground.

  • Mypy version used: 0.991, 0.971
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions