Hacker News new | ask | show | jobs
by atorodius 1641 days 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....

Kind of blew my mind

3 comments

You 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.
Ew. How can there not be some better way to do it?
New to python? It might be big, but it sure is slow!
log4j v2 incoming...