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

Fix ForwardRef equality checks #82134

Closed
plokmijnuhby mannequin opened this issue Aug 26, 2019 · 7 comments
Closed

Fix ForwardRef equality checks #82134

plokmijnuhby mannequin opened this issue Aug 26, 2019 · 7 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@plokmijnuhby
Copy link
Mannequin

plokmijnuhby mannequin commented Aug 26, 2019

BPO 37953
Nosy @ned-deily, @ilevkivskyi, @ZackerySpytz, @miss-islington, @plokmijnuhby
PRs
  • bpo-37953: Fix ForwardRef equality checks #15400
  • bpo-37953:Improve ForwardRef equality checks #15628
  • bpo-37953:Improve ForwardRef equality check #15650
  • [3.8] bpo-37953: Fix ForwardRef hash and equality checks (GH-15400) #16128
  • bpo-37953: Fix deprecation warnings in test_typing #16133
  • [3.8] bpo-37953: Fix deprecation warnings in test_typing (GH-16133) #16138
  • [3.7] bpo-37953: Fix ForwardRef hash and equality checks (GH-15400) #18751
  • 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 2019-09-13.20:05:54.656>
    created_at = <Date 2019-08-26.14:06:04.423>
    labels = ['3.7', '3.8', 'type-bug', 'library', '3.9']
    title = 'Fix ForwardRef equality checks'
    updated_at = <Date 2020-03-03.22:30:18.088>
    user = 'https://github.com/plokmijnuhby'

    bugs.python.org fields:

    activity = <Date 2020-03-03.22:30:18.088>
    actor = 'ned.deily'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-09-13.20:05:54.656>
    closer = 'levkivskyi'
    components = ['Library (Lib)']
    creation = <Date 2019-08-26.14:06:04.423>
    creator = 'plokmijnuhby'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37953
    keywords = ['patch']
    message_count = 7.0
    messages = ['350531', '352389', '352391', '352413', '352419', '352421', '363313']
    nosy_count = 6.0
    nosy_names = ['ned.deily', 'python-dev', 'levkivskyi', 'ZackerySpytz', 'miss-islington', 'plokmijnuhby']
    pr_nums = ['15400', '15628', '15650', '16128', '16133', '16138', '18751']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue37953'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @plokmijnuhby
    Copy link
    Mannequin Author

    plokmijnuhby mannequin commented Aug 26, 2019

    Apologies for issuing a pull request without an associated issue. I'm kind of new to this. Nevermind, I'm making one now.

    The typing module currently contains a bug where ForwardRefs change their hash and equality once they are evaluated. Consider the following code:

    import typing
    ref = typing.ForwardRef('MyClass')
    ref_ = typing.ForwardRef('MyClass')
    
    
    class MyClass:
        def __add__(self, other: ref): ...
    
    
    # We evaluate one forward reference, but not the other.
    typing.get_type_hints(MyClass.__add__)
    
    # Equality is violated
    print(ref == ref_) # False
    
    # This can cause duplication in Unions.
    # The following prints:
    # typing.Union[ForwardRef('MyClass'), ForwardRef('MyClass')]
    # when it should be: typing.Union[ForwardRef('MyClass')]
    wrong = typing.Union[ref, ref_]
    print(wrong)
    
    # The union also does not compare equality properly
    should_be_equal = typing.Union[ref]
    print(should_be_equal == wrong) # False
    
    # In fact this applies to any generic
    print(typing.Callable[[ref],None] == typing.Callable[[ref_],None]) # False

    @plokmijnuhby plokmijnuhby mannequin added 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 26, 2019
    @ilevkivskyi
    Copy link
    Member

    New changeset e082e7c by Ivan Levkivskyi (plokmijnuhby) in branch 'master':
    bpo-37953: Fix ForwardRef hash and equality checks (GH-15400)
    e082e7c

    @miss-islington
    Copy link
    Contributor

    New changeset e91edfe by Miss Islington (bot) in branch '3.8':
    bpo-37953: Fix ForwardRef hash and equality checks (GH-15400)
    e91edfe

    @ZackerySpytz
    Copy link
    Mannequin

    ZackerySpytz mannequin commented Sep 14, 2019

    There are deprecation warnings in test_typing.

    ./python -m test test_typing
    Run tests sequentially
    0:00:00 load avg: 0.16 [1/1] test_typing
    /home/lubuntu2/cpython/Lib/test/test_typing.py:2382: DeprecationWarning: Please use assertEqual instead.
    self.assertEquals(Union[c1, c1_gth], Union[c1])
    /home/lubuntu2/cpython/Lib/test/test_typing.py:2383: DeprecationWarning: Please use assertEqual instead.
    self.assertEquals(Union[c1, c1_gth, int], Union[c1, int])

    == Tests result: SUCCESS ==

    1 test OK.

    Total duration: 215 ms
    Tests result: SUCCESS

    I've created PR 16133 to fix them.

    @miss-islington
    Copy link
    Contributor

    New changeset d057b89 by Miss Islington (bot) (Zackery Spytz) in branch 'master':
    bpo-37953: Fix deprecation warnings in test_typing (GH-16133)
    d057b89

    @miss-islington
    Copy link
    Contributor

    New changeset 66da347 by Miss Islington (bot) in branch '3.8':
    bpo-37953: Fix deprecation warnings in test_typing (GH-16133)
    66da347

    @ned-deily
    Copy link
    Member

    New changeset 3eff46f by Ryan Rowe in branch '3.7':
    bpo-37953: Fix ForwardRef hash and equality checks (GH-15400) (GH-18751)
    3eff46f

    @ned-deily ned-deily added 3.7 (EOL) end of life 3.8 only security fixes labels Mar 3, 2020
    @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.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants