3 ms·
This is only remotely relevant but I recently learned that the related `dataclasses` is implemented by constructing _string representations_ of functions and ca
by atorodius 5y ago
This is only remotely relevant but I recently learned that the related `dataclasses` is implemented by constructing _string representations_ of functions and calling `exec` on them.
https://github.com/python/cpython/blob/3.10/Lib/dataclasses.py#L529 https://github.com/python/cpython/blob/3.10/Lib/dataclasses....
Kind of blew my mind
- bjourne 5y agoEw. How can there not be some better way to do it?
- keithalewis 5y agoNew to python? It might be big, but it sure is slow!
- Spivak 5y agoYou should look at the older implementation. The whole class itself was made by interpolating a huge string and the exec-ing it but was changed with the ability to dynamically generate classes with type(). Nothing other than motivation and a good proposal is standing in the way of a def() that operates similarly.
- posix86 5y agolog4j v2 incoming...