[issue3974] collections.namedtuple uses exec to create new classes

Kristján Valur Jónsson report at bugs.python.org
Thu May 12 15:53:23 CEST 2011


Kristján Valur Jónsson <kristjan at ccpgames.com> added the comment:

Yes, exec is unholy:)

For embedding Python into a console game we have removed the python compiler.  exec and eval don't work.  This saves space and is also a security feature.  I had to modify the collections module so that namedtuple() just returns tuple.  Fortunately, no part of the standard library that uses namedtuple actually uses the actual names, everyone just uses it as a tuple.  So that approach works.

Another problem with the Eval approach is code duplication.

A third could arguably be that there is no namedtuple base class.

Now, replacing namedtuples with tuples works in the standardlib _currentlyt_, but I'm happy to have found an alternative implementation, for future safety.  I only wish it were not hidden away as a diff in a feature request.

----------
nosy: +krisvale

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3974>
_______________________________________


More information about the Python-bugs-list mailing list