[Bf-committers] Patch: removing use of exec() and eval() from python source

Mathias Panzenböck grosser.meister.morti at gmx.net
Wed Oct 21 05:22:12 CEST 2009


On 10/21/2009 02:03 AM, Martin Poirier wrote:
> 
> 
> --- On Tue, 10/20/09, Mathias Panzenböck <grosser.meister.morti at gmx.net> wrote:
> 
>> Anyway, "evaluating the value means it can convert to
>> whatever type is needed
>> from a string property" is just nonsense when you use %d
>> and %f format strings
>> (as is done right now) because of:
> 
> All of them use - exec("[...] = %s" % value) - right now, so the string property is evaluate. (as it would do in your 3rd example earlier, except it doesn't need to convert to string since it's already assured to be one).
> 

Ok, I don't want to waste more of your time on this, just one last note:
The current code does NOT use %s everywhere. Look at:
https://svn.blender.org/svnroot/bf-blender/trunk/blender/release/scripts/modules/bpy_ops.py

and you'll see things like:
exec("context.%s=%f" % (self.path, self.value))

which will raise a TypeError when self.value is a string.

> That works whether the property you are trying to change is a string, a float, an int, a boolean, ... as long as the string value provided evaluates to the correct type.
>

Still, %r would be better, especially in the string case.

	-panzi


More information about the Bf-committers mailing list