This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author plokmijnuhby
Recipients plokmijnuhby
Date 2019-08-26.14:06:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1566828364.46.0.753751170409.issue37953@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2019-08-26 14:06:04plokmijnuhbysetrecipients: + plokmijnuhby
2019-08-26 14:06:04plokmijnuhbysetmessageid: <1566828364.46.0.753751170409.issue37953@roundup.psfhosted.org>
2019-08-26 14:06:04plokmijnuhbylinkissue37953 messages
2019-08-26 14:06:04plokmijnuhbycreate