Skip to content

tuple.__str__ call __repr__ and not __str__ for underlying items. #127760

@ccossou

Description

@ccossou

Bug report

Bug description:

After numpy 2.0, repr changed for all numpy types (e.g; np.int64 and np.float64).

This had an impact on tuple.str, because it seems that tuple.str refers to item.repr instead of str.

Here, I use Python 3.12.8 and numpy 2.2.0

We now have this behavior:

>>> import numpy as np
>>> x = np.int64(45)
>>> print((x,x))
(np.int64(45), np.int64(45))
>>> print(x)
45

If you use python 3.11.11 and numpy 1.26.0, you had:

>>> import numpy as np
>>> x = np.int64(45)
>>> print((x,x))
(45, 45)
>>> print(x)
45

I personally think that the type has no place in a str conversion, but that's my opinion. Thus, I'm not sure it's a bug or a feature. But I would tend to think that tuple.str should call str and tuple.repr should call repr

CPython versions tested on:

3.11, 3.12

Operating systems tested on:

Linux

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