Skip to content

Fix ForwardRef equality checks #82134

Closed
Closed

Description

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

    Activity

    1. plokmijnuhby commented on Aug 26, 2019

      plokmijnuhbymannequin
      MannequinAuthor

      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
    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Aug 26, 2019
    3. ilevkivskyi commented on Sep 13, 2019

      @ilevkivskyi
      Member

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

    4. miss-islington commented on Sep 13, 2019

      @miss-islington
      Contributor

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

    5. ZackerySpytz commented on Sep 14, 2019

      ZackerySpytzmannequin
      Mannequin

      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.

    6. miss-islington commented on Sep 14, 2019

      @miss-islington
      Contributor

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

    7. miss-islington commented on Sep 14, 2019

      @miss-islington
      Contributor

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

    8. ned-deily commented on Mar 3, 2020

      @ned-deily
      Member

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

    9. 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.7 (EOL)end of life3.8 (EOL)end of life3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions