Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Should we remove sametypes.py? #7924

Closed
@ilevkivskyi

Description

@ilevkivskyi

There are two ways we can compare types for being the same:

  • Semantic identity, this is what is done by is_equivalent() that just checks A <: B and B <: A. This affects semantics of types in the user code being checked.
  • Representation identity, this is what is currently done by Type.__eq__() and Type.__hash__(). This affects internal bookkeeping, caching, etc.

Currently, is_same_types() stays somewhere in the middle, it doesn't take into account some subtype relationships (including protocols and recursive type aliases), but it also "takes into account" make_simplified_union().

I could see how this can be a minor performance optimization for equivalence with respect to proper subtyping, but IMO this kind of middle ground position increases chance for confusion and bugs. I would propose to remove it and instead use == and is_equivalent().

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions