flake8-bugbear icon indicating copy to clipboard operation
flake8-bugbear copied to clipboard

Proposed Check: Warn use of `eval`

Open gopar opened this issue 8 years ago • 4 comments

Thoughts?

gopar avatar Oct 18 '17 21:10 gopar

Can you elaborate a little more on you exact idea of: a) What it check for? (Seems like if it's used you want to warn) b) What you're going to suggest or state as the remediation for the developer.

cooperlees avatar Oct 18 '17 21:10 cooperlees

There's nothing inherently wrong with the use of eval. What would you like the warning to say?

ambv avatar Oct 29 '17 00:10 ambv

I was taught to never use eval, for the times that I thought I needed eval, I instead went with ast.literal_eval. I guess it depends what you're passing into the function.

gopar avatar Oct 29 '17 01:10 gopar

If someone uses eval it is quite explicit that eval is being used.

The original problems with eval come from the old javascript days of developers having no idea how to code the language and using eval and copy-pasting the same code snippets everywhere.

In python so far, all use of eval I've seen and that I've used myself has been solely to work around syntax that is invalid in Python2 or 3, e.g., print or exec being keywords and not functions, or the syntax differences of the raise statement.

I do think eval should be used sparingly, but I doubt there is a big benefit about warning about its use, since it is very explicit that eval is being used somewhere.

joaoe avatar Dec 31 '19 17:12 joaoe