Issue36072
Created on 2019-02-22 05:34 by sir-sigurd, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg336279 - (view) | Author: Sergey Fedoseev (sir-sigurd) * | Date: 2019-02-22 05:34 | |
In [186]: from itertools import cycle
In [187]: class ContainerLike:
...: def __init__(self):
...: self.chars = cycle('12')
...: def __getitem__(self, key):
...: return next(self.chars)
...:
In [188]: 'aaaaaa'.translate(ContainerLike())
Out[188]: '111111'
In [189]: 'ыыыыыы'.translate(ContainerLike())
Out[189]: '121212
It seems that behavior was changed in https://github.com/python/cpython/commit/89a76abf20889551ec1ed64dee1a4161a435db5b. At least it should be documented.
|
|||
| msg336280 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2019-02-22 06:11 | |
You are using a mapping that returns different values for the same key. You should not expect a stable result for it. I do not think this needs a special mentioning in the documentation. Garbage in -- garbage out. |
|||
| msg336893 - (view) | Author: Terry J. Reedy (terry.reedy) * ![]() |
Date: 2019-03-01 04:52 | |
I agree. The fact the CPython attempts to optimize all_ascii.translate(table) is a CPython implementation detail, not a language feature. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:11 | admin | set | github: 80253 |
| 2019-03-01 04:52:36 | terry.reedy | set | status: open -> closed type: enhancement nosy:
+ terry.reedy, docs@python |
| 2019-02-22 06:11:47 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg336280 |
| 2019-02-22 05:44:14 | sir-sigurd | set | title: str.translate() behave differently for ASCII-only and other strings -> str.translate() behaves differently for ASCII-only and other strings |
| 2019-02-22 05:34:29 | sir-sigurd | create | |
