scottrogowski / code2flow

Pretty good call graphs for dynamic languages
MIT License
3.98k stars 295 forks source link

AssertionError? #81

Open boyanpenkov opened 1 year ago

boyanpenkov commented 1 year ago

has anybody seen the following AssertionError?

Traceback (most recent call last):
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/bin/code2flow", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/lib/python3.11/site-packages/code2flow/engine.py", line 860, in main
    code2flow(
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/lib/python3.11/site-packages/code2flow/engine.py", line 734, in code2flow
    file_groups, all_nodes, edges = map_it(sources, language, no_trimming,
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/lib/python3.11/site-packages/code2flow/engine.py", line 478, in map_it
    file_group = make_file_group(file_ast_tree, source, extension)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/lib/python3.11/site-packages/code2flow/engine.py", line 359, in make_file_group
    file_group.add_node(language.make_root_node(body_trees, parent=file_group), is_root=True)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/lib/python3.11/site-packages/code2flow/python.py", line 230, in make_root_node
    calls = make_calls(lines)
            ^^^^^^^^^^^^^^^^^
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/lib/python3.11/site-packages/code2flow/python.py", line 54, in make_calls
    call = get_call_from_func_element(element.func)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/lib/python3.11/site-packages/code2flow/python.py", line 18, in get_call_from_func_element
    assert type(func) in (ast.Attribute, ast.Name, ast.Subscript, ast.Call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

I'm on code2flow 2.5.1, which is the one in conda-forge.

C41Underscore commented 1 year ago

Are you able to provide a bit more information about how you got this error? Was this executed on a single file or a collection of them?

boyanpenkov commented 1 year ago

@C41Underscore -- thanks!

Yes, this was executed on a collection of files (specifically, https://github.com/perrette/papers/tree/master) and the specific command is

(python311) → master Work/papers pwd                                                                                         9:55:12
/home/boyan/boyanshouse/Vazhno/Work/papers
(python311) → master Work/papers code2flow papers --language py --target-function addcmd --upstream-depth=2 --downstream-depth=10
Code2Flow: Found 11 files from sources argument.
Code2Flow: Processing 11 source file(s).
Code2Flow:   papers/__init__.py
Code2Flow:   papers/__main__.py
Code2Flow:   papers/_version.py
Code2Flow:   papers/bib.py
Code2Flow:   papers/config.py
Code2Flow:   papers/duplicate.py
Code2Flow:   papers/encoding.py
Code2Flow:   papers/extract.py
Code2Flow:   papers/filename.py
Code2Flow:   papers/latexenc.py
Code2Flow:   papers/utils.py
Traceback (most recent call last):
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/bin/code2flow", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/lib/python3.11/site-packages/code2flow/engine.py", line 860, in main
    code2flow(
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/lib/python3.11/site-packages/code2flow/engine.py", line 734, in code2flow
    file_groups, all_nodes, edges = map_it(sources, language, no_trimming,
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/lib/python3.11/site-packages/code2flow/engine.py", line 478, in map_it
    file_group = make_file_group(file_ast_tree, source, extension)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/lib/python3.11/site-packages/code2flow/engine.py", line 356, in make_file_group
    for new_node in language.make_nodes(node_tree, parent=file_group):
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/lib/python3.11/site-packages/code2flow/python.py", line 205, in make_nodes
    calls = make_calls(tree.body)
            ^^^^^^^^^^^^^^^^^^^^^
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/lib/python3.11/site-packages/code2flow/python.py", line 54, in make_calls
    call = get_call_from_func_element(element.func)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/lib/python3.11/site-packages/code2flow/python.py", line 18, in get_call_from_func_element
    assert type(func) in (ast.Attribute, ast.Name, ast.Subscript, ast.Call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
MaudOtten commented 1 year ago

Dear both, I am running into the same error. It occurs when I pass a path to a main directory of python scripts, but not if I specify a single script in this directory.

eshaanagarwal commented 5 months ago

Any solution to this problem ??

wistuba commented 3 months ago

I have the same.

How to reproduce:

Python 3.11.9 (not sure this is relevant)

git clone https://github.com/astropy/astropy.git
cd astropy
code2flow astropy

I've looked into the type, one example can be ast.BinOp.

Maybe this is an uncovered case? It happens here: https://github.com/astropy/astropy/blob/main/astropy/modeling/tests/test_compound.py#L554

(poly | shift.inverse)(1)