[Python-ideas] User-defined literals

Guido van Rossum guido at python.org
Thu Jun 4 23:05:29 CEST 2015


OK, you can attribute that to lousy docs. The intention is that builtin
types are immutable.

On Thu, Jun 4, 2015 at 1:18 PM, Andrew Barnert <abarnert at yahoo.com> wrote:

> On Jun 4, 2015, at 12:49, Guido van Rossum <guido at python.org> wrote:
>
> On Thu, Jun 4, 2015 at 12:14 PM, Andrew Barnert via Python-ideas <
> python-ideas at python.org> wrote:
>
>> But this isn't actually true. That BINARY_ADD opcode looks up the
>> addition method at runtime and calls it. And that means that if you
>> monkeypatch complex.__radd__, your method will get called.
>>
>
> Wrong. You can't moneypatch complex.__radd__. That's a feature of the
> language.
>
>
> I may well have missed it, but I went looking through the Built-in Types
> library documentation, the Data Model and other chapters of the language
> reference documentation, and every relevant PEP I could think of, and I
> can't find anything that says this is true.
>
> The best I can find is the rationale section for PEP 3119 saying "there
> are good reasons to keep the built-in types immutable", which is why PEP
> 3141 was changed to not require mutating the built-in types. But "there are
> good reasons to allow implementations to forbid it" isn't the same thing as
> "all implementations must forbid it".
>
> And at least some implementations do allow it, like Brython and one of the
> two embedded pythons. (And the rationale in PEP 3119 doesn't apply to
> them--Brython doesn't share built-in types between different Python
> interpreters in different browser windows, even if they're in the same
> address space.)
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150604/dd28f6f3/attachment-0001.html>


More information about the Python-ideas mailing list