diff options
author | plokmijnuhby <39633434+plokmijnuhby@users.noreply.github.com> | 2019-09-13 19:40:54 (GMT) |
---|---|---|
committer | Ivan Levkivskyi <levkivskyi@gmail.com> | 2019-09-13 19:40:54 (GMT) |
commit | e082e7cbe4a934b86f7a07354d97d4e14a9dd46a (patch) | |
tree | c5aef93f4c813f1cbe7f6158489f72e3a9098974 /Lib/typing.py | |
parent | 77cd0ceab2f6c1696fb1d31115c2f880b2e21934 (diff) | |
download | cpython-e082e7cbe4a934b86f7a07354d97d4e14a9dd46a.zip cpython-e082e7cbe4a934b86f7a07354d97d4e14a9dd46a.tar.gz cpython-e082e7cbe4a934b86f7a07354d97d4e14a9dd46a.tar.bz2 |
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
Diffstat (limited to 'Lib/typing.py')
-rw-r--r-- | Lib/typing.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index 7b07112..3201133 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -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})' |