Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
serhiy-storchaka opened this issue Jul 15, 2021 · 3 comments
Closed

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

serhiy-storchaka opened this issue Jul 15, 2021 · 3 comments
Labels
3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

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']

    @serhiy-storchaka
    Copy link
    Member Author

    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).

    @serhiy-storchaka serhiy-storchaka added 3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jul 15, 2021
    @ambv
    Copy link
    Contributor

    ambv commented Jul 16, 2021

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

    @ambv
    Copy link
    Contributor

    ambv commented Jul 16, 2021

    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

    @ambv ambv closed this as completed Jul 16, 2021
    @ambv ambv closed this as completed Jul 16, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants