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: Improve error message for subscripting non-generic types
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: JelleZijlstra, gvanrossum, kj, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2022-03-05 10:18 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31694 merged serhiy.storchaka, 2022-03-05 10:25
Messages (2)
msg414573 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-03-05 10:18
Currently, if you try to subscript a non-generic type you will get an error:

>>> int[str]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable

Yes, 'type' objects are usually not subscriptable, but list[str] works, and it is not clear from the error message for what type it is failed.

The following PR changes an error message:

>>> int[str]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: type 'int' is not subscriptable
msg414576 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-03-05 13:59
New changeset ab9301a28fa431d7a32163126fc96de3b2ce6107 by Serhiy Storchaka in branch 'main':
bpo-46927: Include the type's name in the error message for subscripting non-generic types (GH-31694)
https://github.com/python/cpython/commit/ab9301a28fa431d7a32163126fc96de3b2ce6107
History
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91083
2022-03-05 14:07:56serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-03-05 13:59:50serhiy.storchakasetmessages: + msg414576
2022-03-05 10:30:45AlexWaygoodsetnosy: + JelleZijlstra
2022-03-05 10:25:20serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request29814
2022-03-05 10:23:14serhiy.storchakasetnosy: + gvanrossum, kj
2022-03-05 10:18:42serhiy.storchakacreate