5 ms·
Really? Huh. I would have expected a metaclass.
by cjbillington 9y ago
Really? Huh. I would have expected a metaclass.
- rajathagasthya 9y agoWhile using a metaclass is indeed cleaner, it's slower than generating code on the fly and exec-ing it. This video talks about it: https://youtu.be/sPiWg5jSoZI?t=1h37m18s https://youtu.be/sPiWg5jSoZI?t=1h37m18s
- Xophmeister 9y agoI guess that's how Python 3.6's typing.NamedTuple works, which is frankly a much nicer syntax for named tuples.
- JelleZijlstra 9y agoIt's not actually; typing.NamedTuple is just a wrapper that calls the original collections.namedtuple. It does provide some additional features, like default values and methods.