SMAT-Lab / Scalpel

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

Running type checker on the code #48

Closed tristanlatr closed 2 years ago

tristanlatr commented 2 years ago

I've run pytype checker on the code and it seems that there are a few error that should be looked into IMO:

pytype run-test: commands[0] | pytype --keep-going scalpel
Computing dependencies
Analyzing 29 sources with 0 local dependencies
ninja: Entering directory `.pytype'
[1/29] check scalpel.core.func_call_visitor
[2/29] check scalpel.cfg.model
FAILED: Scalpel/.pytype/pyi/scalpel/cfg/model.pyi 
Scalpel/.tox/pytype/bin/python -m pytype.single --imports_info Scalpel/.pytype/imports/scalpel.cfg.model.imports --module-name scalpel.cfg.model --platform darwin -V 3.8 -o Scalpel/.pytype/pyi/scalpel/cfg/model.pyi --analyze-annotated --nofail --quick Scalpel/scalpel/cfg/model.py
File "Scalpel/scalpel/cfg/model.py", line 74, in strip_comment: Name 'token' is not defined [name-error]
File "Scalpel/scalpel/cfg/model.py", line 79, in strip_comment: Name 'tokenize' is not defined [name-error]
File "Scalpel/scalpel/cfg/model.py", line 90, in strip_comment: Name 'mod' is not defined [name-error]
File "Scalpel/scalpel/cfg/model.py", line 91, in strip_comment: Name 'token' is not defined [name-error]
File "Scalpel/scalpel/cfg/model.py", line 93, in strip_comment: Name 'mod' is not defined [name-error]
File "Scalpel/scalpel/cfg/model.py", line 94, in strip_comment: Name 'tokenize' is not defined [name-error]
File "Scalpel/scalpel/cfg/model.py", line 96, in strip_comment: Name 'mod' is not defined [name-error]
File "Scalpel/scalpel/cfg/model.py", line 98, in strip_comment: Name 'mod' is not defined [name-error]

For more details, see https://google.github.io/pytype/errors.html#name-error
[3/29] check scalpel.core.fun_def_visitor
[4/29] check scalpel.core.util
[5/29] check scalpel.core.vars_visitor
[6/29] check scalpel.core.class_visitor
[7/29] check scalpel.core.source_visitor
[8/29] check scalpel.typeinfer.utilities
FAILED: Scalpel/.pytype/pyi/scalpel/typeinfer/utilities.pyi 
Scalpel/.tox/pytype/bin/python -m pytype.single --imports_info Scalpel/.pytype/imports/scalpel.typeinfer.utilities.imports --module-name scalpel.typeinfer.utilities --platform darwin -V 3.8 -o Scalpel/.pytype/pyi/scalpel/typeinfer/utilities.pyi --analyze-annotated --nofail --quick Scalpel/scalpel/typeinfer/utilities.py
File "Scalpel/scalpel/typeinfer/utilities.py", line 270, in check_consistent_list_types: bad option 'None' in return type [bad-return-type]
           Expected: str
  Actually returned: Optional[Any]
File "Scalpel/scalpel/typeinfer/utilities.py", line 430, in <module>: Invalid type annotation '<instance of Callable>' for node [invalid-annotation]
  Not a type

For more details, see https://google.github.io/pytype/errors.html
[9/29] check scalpel.typeinfer.visitors
[10/29] check scalpel.typeinfer.__init__
[11/29] check scalpel.typeinfer.classes
FAILED: Scalpel/.pytype/pyi/scalpel/typeinfer/classes.pyi 
Scalpel/.tox/pytype/bin/python -m pytype.single --imports_info Scalpel/.pytype/imports/scalpel.typeinfer.classes.imports --module-name scalpel.typeinfer.classes --platform darwin -V 3.8 -o Scalpel/.pytype/pyi/scalpel/typeinfer/classes.pyi --analyze-annotated --nofail --quick Scalpel/scalpel/typeinfer/classes.py
File "Scalpel/scalpel/typeinfer/classes.py", line 31, in ScalpelVariable: Type annotation for type does not match type of assignment [annotation-type-mismatch]
  Annotation: str (Did you mean 'typing.Optional[str]'?)
  Assignment: None
File "Scalpel/scalpel/typeinfer/classes.py", line 35, in ScalpelVariable: Type annotation for called_methods does not match type of assignment [annotation-type-mismatch]
  Annotation: List[str] (Did you mean 'typing.Optional[List[str]]'?)
  Assignment: None
File "Scalpel/scalpel/typeinfer/classes.py", line 36, in ScalpelVariable: Type annotation for binary_operation does not match type of assignment [annotation-type-mismatch]
  Annotation: _ast.BinOp (Did you mean 'typing.Optional[_ast.BinOp]'?)
  Assignment: None
File "Scalpel/scalpel/typeinfer/classes.py", line 46, in ScalpelFunction: Type annotation for return_type does not match type of assignment [annotation-type-mismatch]
  Annotation: str (Did you mean 'typing.Optional[str]'?)
  Assignment: None
File "Scalpel/scalpel/typeinfer/classes.py", line 56, in ScalpelClass: Type annotation for inherits does not match type of assignment [annotation-type-mismatch]
  Annotation: List[str] (Did you mean 'typing.Optional[List[str]]'?)
  Assignment: None
File "Scalpel/scalpel/typeinfer/classes.py", line 65, in BinaryOperation: Invalid type annotation '<instance of Callable>' for left_ast_type [invalid-annotation]
  Not a type
File "Scalpel/scalpel/typeinfer/classes.py", line 67, in BinaryOperation: Invalid type annotation '<instance of Callable>' for right_ast_type [invalid-annotation]
  Not a type
File "Scalpel/scalpel/typeinfer/classes.py", line 68, in BinaryOperation: Invalid type annotation '<instance of Callable>' for operator [invalid-annotation]
  Not a type
File "Scalpel/scalpel/typeinfer/classes.py", line 69, in BinaryOperation: Type annotation for shared_type does not match type of assignment [annotation-type-mismatch]
  Annotation: str (Did you mean 'typing.Optional[str]'?)
  Assignment: None

For more details, see https://google.github.io/pytype/errors.html#import-error
[14/29] check scalpel.rewriter
FAILED: Scalpel/.pytype/pyi/scalpel/rewriter.pyi 
Scalpel/.tox/pytype/bin/python -m pytype.single --imports_info Scalpel/.pytype/imports/scalpel.rewriter.imports --module-name scalpel.rewriter --platform darwin -V 3.8 -o Scalpel/.pytype/pyi/scalpel/rewriter.pyi --analyze-annotated --nofail --quick Scalpel/scalpel/rewriter.py
File "Scalpel/scalpel/rewriter.py", line 53, in random_var_renaming: Invalid keyword argument skip_call_name to function scalpel.core.vars_visitor.get_vars [wrong-keyword-args]
         Expected: (node)
  Actually passed: (node, skip_call_name)
File "Scalpel/scalpel/rewriter.py", line 210, in insert_before: No attribute 'pattern' on ASTRewriter [attribute-error]
File "Scalpel/scalpel/rewriter.py", line 225, in insert_after: No attribute 'pattern' on ASTRewriter [attribute-error]
File "Scalpel/scalpel/rewriter.py", line 234, in remove: No attribute 'pattern' on ASTRewriter [attribute-error]
File "Scalpel/scalpel/rewriter.py", line 244, in replace: No attribute 'pattern' on ASTRewriter [attribute-error]

For more details, see https://google.github.io/pytype/errors.html
[15/29] check scalpel.SSA.alg
[16/29] check scalpel.import_graph.__init__
[17/29] check scalpel.__init__
[18/29] check scalpel.call_graph.__init__
[19/29] check scalpel.SSA.__init__
[20/29] check scalpel.core.kw_visitor
[21/29] check scalpel.core.__init__
[22/29] check scalpel.util
ninja: build stopped: cannot make progress due to previous errors.
Leaving directory '.pytype'

Tell me what you think,

Jarvx commented 2 years ago

Thanks for reporting. I think we will need to improve code quality next.

Jarvx commented 2 years ago

Thanks for checking the code for us!. I've pushed fixes and will release the new one soon.