Skip to content

Missing carets when reporting an "object is not callable" error #128832

@PierreQuentel

Description

@PierreQuentel

Bug report

Bug description:

There is a minor inconsistency between the way "not subscriptable" and "not callable" errors are reported.

When an object is not subscriptable, the exception trace includes the carets ~ and ^ for the subscript value and slice.

>>> t = 0
>>> t[0]
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    t[0]
    ~^^^
TypeError: 'int' object is not subscriptable

The carets are also displayed if the attempted subscript is assigned

>>> x = t[0]
Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    x = t[0]
        ~^^^
TypeError: 'int' object is not subscriptable

It is the same when an object is not callable

>>> t(0)
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    t(0)
    ~^^^
TypeError: 'int' object is not callable

but when the attempted call is assigned, we lose the carets

>>> x = t(0)
Traceback (most recent call last):
  File "<python-input-5>", line 1, in <module>
    x = t(0)
TypeError: 'int' object is not callable

instead of the expected

>>> x = t(0)
Traceback (most recent call last):
  File "<python-input-5>", line 1, in <module>
    x = t(0)
        ~^^^
TypeError: 'int' object is not callable

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions