Skip to content

Confusing traceback: Incorrect error line shown when @property is mistakenly applied to __str__ method #140311

@Ark-kun

Description

@Ark-kun

Bug report

Bug description:

The error message is TypeError: 'str' object is not callable, but the highlighted error line has no calls.

class MyClass:
    @property
    def __str__(self):
        return "MyClass"

obj = MyClass()

print(f"Hello, {obj}")
Traceback (most recent call last):
  File "<string>", line 9, in <module>
    print(f"Hello, {obj}")
                   ^^^^^
TypeError: 'str' object is not callable

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions