mirror of
https://github.com/python/cpython.git
synced 2025-08-10 03:49:18 +00:00
bpo-37953: Fix ForwardRef hash and equality checks (GH-15400)
Ideally if we stick a ForwardRef in a dictionary we would like to reliably be able to get it out again.
https://bugs.python.org/issue37953
(cherry picked from commit e082e7cbe4
)
Co-authored-by: plokmijnuhby <39633434+plokmijnuhby@users.noreply.github.com>
This commit is contained in:
parent
cd85200f6d
commit
e91edfed42
3 changed files with 123 additions and 3 deletions
|
@ -524,11 +524,13 @@ class ForwardRef(_Final, _root=True):
|
|||
def __eq__(self, other):
|
||||
if not isinstance(other, ForwardRef):
|
||||
return NotImplemented
|
||||
return (self.__forward_arg__ == other.__forward_arg__ and
|
||||
self.__forward_value__ == other.__forward_value__)
|
||||
if self.__forward_evaluated__ and other.__forward_evaluated__:
|
||||
return (self.__forward_arg__ == other.__forward_arg__ and
|
||||
self.__forward_value__ == other.__forward_value__)
|
||||
return self.__forward_arg__ == other.__forward_arg__
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self.__forward_arg__, self.__forward_value__))
|
||||
return hash(self.__forward_arg__)
|
||||
|
||||
def __repr__(self):
|
||||
return f'ForwardRef({self.__forward_arg__!r})'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue