Override built in types... possible? or proposal.

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu May 31 19:50:34 EDT 2018


On Thu, 31 May 2018 09:51:30 -0700, Rob Gaddi wrote:

> On 05/31/2018 07:49 AM, Dan Strohl wrote:
>> Is it possible to override the assignment of built in types to the
>> shorthand representations?   And if not, is it a reasonable thought to
>> consider adding?
[...]

> My problem with this idea is that it breaks expectations.

No worse than shadowing builtin names.



> If I know one
> thing as a Python programmer, it's that 'Bob' is a str.

True. But if there were such a feature as Dan asked for, you would learn 
that "Bob" might be anything, depending on the current state of the 
module. That's not much worse than the idea that int("123") might return 
anything, depending on the current state of the module and builtins.

Still, I agree that this is probably a tad too much dynamism even for a 
language as dynamic as Python.


-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson




More information about the Python-list mailing list