pre-commit/pygrep-hooks

[python-no-eval] matches `obj.eval()`

randolf-scholz opened this issue · 5 comments

For example, model.eval() gets matched.

entry: '\beval\('

The regex should be changed to something like (?<!(\w\.))eval\(

search the issue tracker, there are several duplicates

@asottile Can you please specify the exact duplicate that points to a fix? This is all I see in the issue tracker:
image

Further: I am also getting a false positive when using polars.Expr.arr.eval, which is not related to builtins.eval in any fashion.

Example usage of arr.eval as shown here, is used for calculating set intersection:

df.with_column(
    pl.col("a")
    .arr.concat('b')
    # python-no-eval throws an error here:
    .arr.eval(pl.element().filter(pl.count().over(pl.element()) == 2))
    .alias('filtered')
)

have you read them?

At most I find a closed PR where you state "bad apis should not be allowed".

I can understand the sentiment, but as it stands, this check is now causing a problem with a specific use case, and unless there's a mechanism provided to exclude that line from the check, I have to disable the hook.

I'm glad you found a solution. next time please just find it instead of taking time out of my day and at mentioning me