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.

classification
Title: Type (typing) objects are hashable and comparable for equality but this is not documented
Type: enhancement Stage:
Components: Documentation Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, gdr@garethrees.org, gvanrossum, levkivskyi
Priority: normal Keywords:

Created on 2016-07-22 09:50 by gdr@garethrees.org, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg270981 - (view) Author: Gareth Rees (gdr@garethrees.org) * (Python triager) Date: 2016-07-22 09:50
The type objects constructed by the metaclasses in the typing module are hashable and comparable for equality:

    >>> from typing import *
    >>> {Mapping[str, int], Mapping[int, str]}
    {typing.Mapping[int, str], typing.Mapping[str, int]}
    >>> Union[str, int, float] == Union[float, int, str]
    True
    >>> List[int] == List[float]
    False

but this is not clearly documented in the documentation for the typing module (there are a handful of examples using equality, but it's not explicit that these are runnable).

It would be nice if there were explicit documentation for these properties of type objects.
msg270997 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2016-07-22 16:23
I am not sure that this feature will survive the resolution of https://github.com/python/typing/issues/136

Types in typing are primarily intended for use with static type checkers and similar tools, their runtime properties are still under some discussions.
msg278337 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2016-10-09 03:18
Fixed by the changes for issue #28388.
History
Date User Action Args
2022-04-11 14:58:34adminsetgithub: 71775
2016-10-09 03:18:21gvanrossumsetstatus: open -> closed

nosy: + gvanrossum
messages: + msg278337

resolution: fixed
2016-07-22 16:23:37levkivskyisetnosy: + levkivskyi
messages: + msg270997
2016-07-22 14:06:05r.david.murraysettitle: Type objects are hashable and comparable for equality but this is not documented -> Type (typing) objects are hashable and comparable for equality but this is not documented
2016-07-22 09:50:51gdr@garethrees.orgcreate