SMAT-Lab / Scalpel

Scalpel: The Python Static Analysis Framework
Apache License 2.0
278 stars 42 forks source link

Constant Propagation: Variables that represent callables are not covered #67

Closed simisimon closed 1 year ago

simisimon commented 1 year ago

In the following example, a callable is passed as a variable to a parameter:

def preprocessing(s):
    return s

v = TfidfVectorizer(analyzer=preprocessing)

Running Scalpel results into the following const_dict:

{('preprocessing', 0): None, ('v', 0): <ast.Call object at 0x0000016BCDE2AAC0>}

In this case, the function def should be assigned to the variable preprocessing instead if None.

Jarvx commented 1 year ago

Hi I am a bit confused, for a function name, what value do you think we should link the name?

simisimon commented 1 year ago

I would expect that the ast.FunctionDef is assigned to the variable/callable preprocessing. So, the resulting const_dict would look like this: {('preprocessing', 0): <ast.FunctionDef object at ..... >, ('v', 0): <ast.Call object at 0x0000016BCDE2AAC0>}

Jarvx commented 1 year ago

Thanks, it looks you have implemented that. If possible, can you please create a PR?

simisimon commented 1 year ago

I already created a PR and I also linked it to this issue here.

Jarvx commented 1 year ago

I already created a PR and I also linked it to this issue here.

Thanks for your contribution!