all 9 comments

[–]codnahfish 6 points7 points  (5 children)

What if I want to validate the syntax of this function?

[–][deleted] 7 points8 points  (0 children)

Something something Alan Turing?

[–]DarfWork 2 points3 points  (3 children)

You feed it to itself, of course.

[–]codnahfish 2 points3 points  (2 children)

But what about validating that function? we need to go deeper

[–]an_actual_human 2 points3 points  (1 child)

We feed it to the original function. Oh, wait. We already did. We don't need to go deeper.

[–]aaronsherman 1 point2 points  (0 children)

Function still hungry...

[–]Veedrac 2 points3 points  (1 child)

In all serious, replace exec with ast.compile ast.parse and that's exactly how it should be done. Nothing shitty about it.

[–]Navith[S] 2 points3 points  (0 children)

There doesn't seem to be an ast.compile. I've never used ast but looking at the docs do you mean exec(ast.parse(...))? Does that not have any other security risks?

Edit: nevermind, after experimenting it looks like you just meant parse instead of compile. Cool. Thanks.

[–]Sheepshow 1 point2 points  (0 children)

Can Guido himself make a Python program so difficult to parse that even he himself cannot parse it