SMAT-Lab / Scalpel

Scalpel: The Python Static Analysis Framework
Apache License 2.0
286 stars 43 forks source link

AttributeErrors caused by vars visitor #29

Closed simisimon closed 2 years ago

simisimon commented 2 years ago

I found again several problems caused by the vars visitor module when analyzing ML projects. To reproduce the errors, run the following example:

# AttributeError: 'int' object has no attribute '_fields'
code_str = """x = np.zeros(([Y.shape[0],X.shape[0]]))"""   

# AttributeError: 'Name' object has no attribute 'value'
# code_str = """z = np.array([x.test[i] for i in test])"""   

# AttributeError: 'Call' object has no attribute 'value'
# code_str = """best_tune = param_grid_list[tune_accs.index(max(tune_accs))]""" 

cfg = CFGBuilder().build_from_src(name="", src=code_str)

_, const_dict = SSA().compute_SSA(cfg)

Just change the code_str variable, to see the different errors. There are probably more errors. I try to add all the cases that I find.

If you need more information, just let me know.

simisimon commented 2 years ago

Here is a code string that causes another error:

# AttributeError: 'str' object has no attribute '_fields'
code_str = """step['Model'] = model_name"""
Jarvx commented 2 years ago

Thanks for raising this. Can you let me know your Python version as I could not reproduce this problem?

simisimon commented 2 years ago

I'm using Python 3.9.0. I got the same problems with Python 3.9.5.

Jarvx commented 2 years ago

The problem has now been fixed. This is due to syntax changes in the latest Python version. Thanks for offering this!.