Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TypeError: object of type 'Token' has no len() #377

Closed
@dkw72n

Description

@dkw72n

Description

The following exception raised on certain input:

Traceback (most recent call last):
  File "test_pythonlib.py", line 311, in <module>
    do_tests(src_dir, pattern, target_dir, test_opts)
  File "test_pythonlib.py", line 212, in do_tests
    src_dir, target_dir, files, [], do_verify=opts["do_verify"]
  File "/tmp/python-uncompyle6/uncompyle6/main.py", line 312, in main
    do_fragments,
  File "/tmp/python-uncompyle6/uncompyle6/main.py", line 215, in decompile_file
    do_fragments=do_fragments,
  File "/tmp/python-uncompyle6/uncompyle6/main.py", line 134, in decompile 
    co, out, bytecode_version, debug_opts=debug_opts, is_pypy=is_pypy
  File "/tmp/python-uncompyle6/uncompyle6/semantics/pysource.py", line 2604, in code_deparse
    deparsed.ast = deparsed.build_ast(tokens, customize, co, isTopLevel=isTopLevel)
  File "/tmp/python-uncompyle6/uncompyle6/semantics/pysource.py", line 2544, in build_ast 
    transform_ast = self.treeTransform.transform(ast, code)
  File "/tmp/python-uncompyle6/uncompyle6/semantics/transform.py", line 449, in transform 
    self.ast = self.traverse(self.ast, is_lambda=False)
  File "/tmp/python-uncompyle6/uncompyle6/semantics/transform.py", line 443, in traverse
    node = self.preorder(node)
  File "/tmp/python-uncompyle6/uncompyle6/semantics/transform.py", line 103, in preorder
    node[i] = self.preorder(kid)
  File "/tmp/python-uncompyle6/uncompyle6/semantics/transform.py", line 103, in preorder
    node[i] = self.preorder(kid)
  File "/tmp/python-uncompyle6/uncompyle6/semantics/transform.py", line 103, in preorder
    node[i] = self.preorder(kid)
  [Previous line repeated 3 more times]
  File "/tmp/python-uncompyle6/uncompyle6/semantics/transform.py", line 98, in preorder
    node = func(node)
  File "/tmp/python-uncompyle6/uncompyle6/semantics/transform.py", line 296, in n_ifelsestmt
    if len_n == 1 == len(n[0]) and n[0] == "stmt":
TypeError: object of type 'Token' has no len()

How to Reproduce

compile the following code with python2.7 as an input:

for name in slots:
    if y:
        pass
    else:
        continue
        if x:
            y()
        else:
            z()

Expected behavior

no exception raised

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions