summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorRyan Rowe <ryanf.rowe@gmail.com>2020-03-03 22:29:40 (GMT)
committerGitHub <noreply@github.com>2020-03-03 22:29:40 (GMT)
commit3eff46fc7d2e3c80c4dedba4177782f1fc8ad89b (patch)
tree0c5e7950104d13b3ebdaf72b1b876a82620df043 /Lib/typing.py
parentf8f163c38f29e409b044e17afb01ca38485a7227 (diff)
downloadcpython-3eff46fc7d2e3c80c4dedba4177782f1fc8ad89b.zip
cpython-3eff46fc7d2e3c80c4dedba4177782f1fc8ad89b.tar.gz
cpython-3eff46fc7d2e3c80c4dedba4177782f1fc8ad89b.tar.bz2
bpo-37953: Fix ForwardRef hash and equality checks (GH-15400) (GH-18751)
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 e082e7c) Co-authored-by: plokmijnuhby <39633434+plokmijnuhby@users.noreply.github.com>
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 3b2e372..1749c2f 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -473,11 +473,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})'