Skip to content

hash() of the unity type is not consistent with equality #88812

Closed

Description

@serhiy-storchaka
BPO 44646
Nosy @gvanrossum, @ambv, @serhiy-storchaka, @JelleZijlstra, @miss-islington, @Fidget-Spinner
PRs
  • bpo-44646: Fix the hash of the union type. #27179
  • [3.10] bpo-44646: Fix the hash of the union type. (GH-27179) #27180
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-07-16.09:03:39.127>
    created_at = <Date 2021-07-15.16:28:49.070>
    labels = ['interpreter-core', 'type-bug', '3.10', '3.11']
    title = 'hash() of the unity type is not consistent with equality'
    updated_at = <Date 2021-07-16.09:03:39.126>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2021-07-16.09:03:39.126>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-07-16.09:03:39.127>
    closer = 'lukasz.langa'
    components = ['Interpreter Core']
    creation = <Date 2021-07-15.16:28:49.070>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44646
    keywords = ['patch']
    message_count = 3.0
    messages = ['397567', '397603', '397604']
    nosy_count = 6.0
    nosy_names = ['gvanrossum', 'lukasz.langa', 'serhiy.storchaka', 'JelleZijlstra', 'miss-islington', 'kj']
    pr_nums = ['27179', '27180']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue44646'
    versions = ['Python 3.10', 'Python 3.11']

    Activity

    1. serhiy-storchaka commented on Jul 15, 2021

      @serhiy-storchaka
      MemberAuthor

      There is a rule: equal hashable objects should have the same hash. The unity type violates it.

      >>> x = int | str
      >>> y = str | int
      >>> x == y
      True
      >>> hash(x) == hash(y)
      False

      And hashes of equal unity type and typing.Union are different too.

      >>> import typing
      >>> z = typing.Union[int, str]
      >>> x == z
      True
      >>> hash(x) == hash(z)
      False

      There is also a problem with a single type (see bpo-44636).

    2. added
      3.11only security fixes
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      type-bugAn unexpected behavior, bug, or error
      on Jul 15, 2021
    3. ambv commented on Jul 16, 2021

      @ambv
      Contributor

      New changeset aeaa553 by Serhiy Storchaka in branch 'main':
      bpo-44646: Fix the hash of the union type. (bpo-27179)
      aeaa553

    4. ambv commented on Jul 16, 2021

      @ambv
      Contributor

      New changeset 7059880 by Miss Islington (bot) in branch '3.10':
      bpo-44646: Fix the hash of the union type. (GH-27179) (bpo-27180)
      7059880

    5. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of life3.11only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions