News for hackers. Stuff that matters.
Re:Python strings are immutable, but only sometimes by postit on Monday February 15, 2021 @03:37PM (#26147015)
I just spend two days chasing a bug because someone shoved a variable inside a dataclass in the wrong place, nothing is immutable in python.
Re:Python strings are immutable, but only sometimes by iainmerrick on Monday February 15, 2021 @04:02PM (#26147334)
No, strings are immutable, despite the semantic gymnastics this article is performing.
Re:Python strings are immutable, but only sometimes by masklinn on Monday February 15, 2021 @04:07PM (#26147406)
Strings are immutable on the Python side. On the C size, however, PyUnicode_Resize is part of the PEP 384 Stable ABI and very specifically tries to resize the string in-place (it's normally intended for string-building).
Re:Python strings are immutable, but only sometimes by ymbeld on Monday February 15, 2021 @05:22PM (#26148319)
If it is immutable from the client’s perspective, it’s immutable. Anything else is ill-defined.
Re:Python strings are immutable, but only sometimes by masklinn on Monday February 15, 2021 @05:27PM (#26148390)
The C api is “from a client’s perspective”. Any rando can build native modules with it.
Re:Python strings are immutable, but only sometimes by ymbeld on Tuesday February 16, 2021 @09:12AM (#26154004)
I stand corrected.
Re:Python strings are immutable, but only sometimes by mcv on Tuesday February 16, 2021 @05:00AM (#26152525)
In javascript I enforce immutability by hitting people over the head when they try to mutate something they're not supposed to.