[Python-Dev] subclassing builtin data structures (original) (raw)
Ethan Furman ethan at stoneleaf.us
Fri Feb 13 01:36:51 CET 2015
- Previous message: [Python-Dev] PEP 486: Make the Python Launcher aware of virtual environments
- Next message: [Python-Dev] subclassing builtin data structures
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I suspect the last big hurdle to making built-in data structures nicely subclassable is the insistence of such types to return new instances as the base class instead of the derived class.
In case that wasn't clear ;)
--> class MyInt(int): ... def repr(self): ... return 'MyInt(%d)' % self ... --> m = MyInt(42) --> m MyInt(42) --> m + 1 43 --> type(m+1) <class 'int'>
Besides the work it would take to rectify this, I imagine the biggest hurdle would be the performance hit in always looking up the type of self. Has anyone done any preliminary benchmarking? Are there other concerns?
--
Ethan
-------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: <http://mail.python.org/pipermail/python-dev/attachments/20150212/7205ef4c/attachment.sig>
- Previous message: [Python-Dev] PEP 486: Make the Python Launcher aware of virtual environments
- Next message: [Python-Dev] subclassing builtin data structures
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]