Skip to content

join is not always permutation invariant #19551

@randolf-scholz

Description

@randolf-scholz

In theory, join(a, b) should always give the same result as join(b, a) (permutation invariance). However, this is not always the case. One example I found is the following (related to the testAbstractTypeInADict unit test)

https://mypy-play.net/?mypy=1.17.0&python=3.12&gist=e4df640a72c4f61c1a33a50db60fd6e5

class Class: ...

def join[T](x: T, y: T) -> T: ...

klass: type[Class]

reveal_type(klass)  # N: Revealed type is "type[__main__.Class]"
reveal_type(Class)  # N: "def () -> __main__.Class"

reveal_type(join(klass, Class))  # N: Revealed type is "builtins.type"
reveal_type(join(Class, klass))  # N: Revealed type is "builtins.object"

Moreover, when debugging this, mypy actually evaluates both is_subtype(left, right) and is_subtype(right, left) to true.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy