Title: typing.Literal: args must be hashable, not immutable
Type: Stage: resolved
Components: Documentation Versions: Python 3.10, Python 3.9
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Jelle Zijlstra Nosy List: Jelle Zijlstra, kj, lukasz.langa, miss-islington
Priority: normal Keywords: patch

Created on 2021-05-01 17:15 by Jelle Zijlstra, last changed 2021-05-05 10:04 by kj. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25877 merged Jelle Zijlstra, 2021-05-04 04:05
PR 25882 merged miss-islington, 2021-05-04 08:54
PR 25897 merged Jelle Zijlstra, 2021-05-04 16:04
Messages (5)
msg392608 - (view) Author: Jelle Zijlstra (Jelle Zijlstra) * (Python triager) Date: 2021-05-01 17:15
After the changes from bpo-42345, the Literal documentation claims that "Literal objects will now raise a TypeError exception during equality comparisons if one of their parameters are not immutable." But in fact it's *unhashable* types that raise an error; mutable but hashable types such as functions or custom objects work fine.

I'll submit a PR for this but may wait until GH-25787 is resolved.
msg392867 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-05-04 09:17
New changeset 2046fb35e4e0986523bd0f6214fc318a414c8b97 by Miss Islington (bot) in branch '3.10':
bpo-44001: improve Literal documentation (GH-25877) (#25882)
msg392908 - (view) Author: Ken Jin (kj) * (Python triager) Date: 2021-05-04 15:07
Jelle, thanks for fixing up the docs. You're right here - anything that can be an element in a frozenset or used as a key in a dict works. And the current docs for sets says that means anything hashable:

If you feel anything's amiss. Please don't hesitate to re-open this issue.
msg392914 - (view) Author: Ken Jin (kj) * (Python triager) Date: 2021-05-04 16:09
Well something was amiss: the 3.9 backport PR ;-).

Sorry for closing this issue too early. I didn't notice there was still one more to go.
msg392917 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-05-04 16:48
New changeset ab0a54adad8ddf488ccfb92970be9e4027673d19 by Jelle Zijlstra in branch '3.9':
[3.9] bpo-44001: improve Literal documentation (GH-25877). (#25897)
Date User Action Args
2021-05-05 10:04:22kjsetstatus: open -> closed
resolution: fixed
2021-05-04 16:48:49lukasz.langasetmessages: + msg392917
2021-05-04 16:09:14kjsetstatus: closed -> open
resolution: fixed -> (no value)
messages: + msg392914
2021-05-04 16:04:48Jelle Zijlstrasetpull_requests: + pull_request24569
2021-05-04 15:07:43kjsetstatus: open -> closed

nosy: + kj
messages: + msg392908

resolution: fixed
stage: patch review -> resolved
2021-05-04 09:17:38lukasz.langasetnosy: + lukasz.langa
messages: + msg392867
2021-05-04 08:54:22miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request24557
2021-05-04 04:05:32Jelle Zijlstrasetkeywords: + patch
stage: patch review
pull_requests: + pull_request24554
2021-05-01 17:15:22Jelle Zijlstracreate