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: Python keywords as string keys in TypedDict
Type: enhancement Stage: resolved
Components: Versions: Python 3.11
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Doug Hoskisson, gvanrossum, serhiy.storchaka, terry.reedy
Priority: normal Keywords:

Created on 2021-08-14 18:28 by Doug Hoskisson, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg399595 - (view) Author: Doug Hoskisson (Doug Hoskisson) Date: 2021-08-14 18:28
I'm running into an issue with the syntax of https://www.python.org/dev/peps/pep-0589/

```
class C(TypedDict):
    to: int
    from: int
	
SyntaxError: invalid syntax
```

I'm not sure any change needs to be made to the specification.
But the interpreter needs to recognize that `from` is a string key to a `TypedDict`, not the keyword `from`.

Or if you don't want to have to recognize `from` as a string instead of a keyword, we need a specification that allows us to put keywords as keys in `TypedDict`.

I was thinking maybe something like:
```
class C(TypedDict):
	"to": int
	"from": int
```
as an optional way to write the same thing.
msg399648 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-08-16 10:53
You can use the functional form of TypedDict:

C = TypedDict("C", {"to": int, "from": int})
msg399996 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-08-20 21:43
The current behavior is not a bug, so this is an enhancement proposal.
msg399998 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-08-20 22:01
Unfortunately you can’t use Python keywords in such positions and we have no plans to fix this. Serhiy’s workaround is the best you can do.
History
Date User Action Args
2022-04-11 14:59:48adminsetgithub: 89078
2021-08-20 22:01:49gvanrossumsetstatus: open -> closed
resolution: wont fix
messages: + msg399998

stage: resolved
2021-08-20 21:43:39terry.reedysetversions: + Python 3.11, - Python 3.8, Python 3.9
nosy: + gvanrossum, terry.reedy

messages: + msg399996

type: behavior -> enhancement
2021-08-16 10:53:24serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg399648
2021-08-14 18:28:18Doug Hoskissoncreate