[New-bugs-announce] [issue46927] Improve error message for subscripting non-generic types

Serhiy Storchaka report at bugs.python.org
Sat Mar 5 05:18:42 EST 2022


New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:

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

----------
components: Interpreter Core
messages: 414573
nosy: serhiy.storchaka
priority: normal
severity: normal
status: open
title: Improve error message for subscripting non-generic types
type: enhancement
versions: Python 3.11

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


More information about the New-bugs-announce mailing list