[New-bugs-announce] [issue24912] The type of cached objects is mutable
Serhiy Storchaka
report at bugs.python.org
Sat Aug 22 00:02:50 CEST 2015
New submission from Serhiy Storchaka:
The type of non-heap types can be changed in 3.5. This means that the type of cached immutable objects such as small ints, empty or 1-character strings, etc can be changed.
>>> class I(int):
... __slots__ = ()
... def __repr__(self):
... return 'Answer to The Ultimate Question of Life, the Universe, and Everything'
... def __add__(self, other):
... return self * other
...
>>> (42).__class__ = I
>>> ord('*')
Answer to The Ultimate Question of Life, the Universe, and Everything
>>> x = 42; x + 2
84
>>> class S(str):
... __slots__ = ()
... def __len__(self):
... return 123
...
>>> 'a'.__class__ = S
>>> i = 1; len('abc'[:i])
123
----------
components: Interpreter Core
messages: 248981
nosy: pitrou, serhiy.storchaka
priority: high
severity: normal
status: open
title: The type of cached objects is mutable
type: behavior
versions: Python 3.5, Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24912>
_______________________________________
More information about the New-bugs-announce
mailing list