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: Invalid example for typing
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.10
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: bozhiyou, docs@python, loganasherjones
Priority: normal Keywords:

Created on 2021-10-18 22:13 by bozhiyou, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg404232 - (view) Author: Bozhi You (bozhiyou) Date: 2021-10-18 22:13
The first example snippet under https://docs.python.org/3/library/typing.html#type-aliases is invalid to run.

```
Traceback (most recent call last):
  File "main.py", line 1, in <module>
    Vector = list[float]
TypeError: 'type' object is not subscriptable
```

A solution to this may be replacing `list` with `List` from `typing`.
msg404255 - (view) Author: Logan Jones (loganasherjones) * Date: 2021-10-19 00:33
Hi Bozhi. The syntax that you're referencing was added in 3.9. So if you're trying the syntax in earlier versions of Python, it won't work. The standard collections were added in PEP 585 (https://www.python.org/dev/peps/pep-0585/)

I think the reason the examples use this syntax is that the previous List classes were deprecated in favor of the new syntax.

Hope this helps!
msg406486 - (view) Author: Bozhi You (bozhiyou) Date: 2021-11-17 19:20
My bad. Didn't notice the version constraint. Thank you, Logan!
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89681
2021-11-17 19:20:17bozhiyousetstatus: pending -> closed

messages: + msg406486
stage: resolved
2021-10-22 19:53:37eric.araujosetstatus: open -> pending
type: compile error -> behavior
resolution: not a bug
2021-10-19 00:33:02loganasherjonessetnosy: + loganasherjones
messages: + msg404255
2021-10-18 22:13:39bozhiyoucreate