[New-bugs-announce] [issue44915] Python keywords as string keys in TypedDict

Doug Hoskisson report at bugs.python.org
Sat Aug 14 14:28:18 EDT 2021


New submission from Doug Hoskisson <beauxq at gmail.com>:

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.

----------
messages: 399595
nosy: Doug Hoskisson
priority: normal
severity: normal
status: open
title: Python keywords as string keys in TypedDict
type: behavior
versions: Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44915>
_______________________________________


More information about the New-bugs-announce mailing list