Author eric.smith
Recipients eric.smith, inada.naoki, ncoghlan, rhettinger, serhiy.storchaka, xiang.zhang
Date 2016-11-08.22:17:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1478643434.38.0.266750331876.issue28638@psf.upfronthosting.co.za>
In-reply-to
Content
This file is derived from my namedlist project on PyPI.

I've stripped out the namedlist stuff, and just left namedtuple. I've also removed the Python 2 support, and I've removed support for default parameters. After that surgery, I have not tested it very well.

Those are my excuses for why the code is more complex that it would be if I were writing it from scratch.

Anyway, instead of using eval() of a string to create the new() function, I use ast manipulations to generate a function that does all of the correct type checking. It calls eval() too, of course, but with a code object.

I originally wrote this as an exercise in learning how to generate AST's. I can't say it's the best way to solve this problem, and I haven't benchmarked it ever. So just consider it as a proof of concept, or ignore it if you're not interested.
History
Date User Action Args
2016-11-08 22:17:14eric.smithsetrecipients: + eric.smith, rhettinger, ncoghlan, inada.naoki, serhiy.storchaka, xiang.zhang
2016-11-08 22:17:14eric.smithsetmessageid: <1478643434.38.0.266750331876.issue28638@psf.upfronthosting.co.za>
2016-11-08 22:17:14eric.smithlinkissue28638 messages
2016-11-08 22:17:14eric.smithcreate