yowoda / autopep695

Automatically upgrade to the new type syntax introduced in PEP 695 using a single command
MIT License
5 stars 0 forks source link

Exception: Expected a SimpleStatementLine but got a SimpleStatementSuite! #5

Closed john-parton closed 2 days ago

john-parton commented 1 week ago

Steps to reproduce

Traceback doesn't tell me which actual file produced the error. I have about 5k files, so it's not clear which one triggered the error.

Expected result

Should not produce an error.

Actual result

Traceback (most recent call last):
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/bin/autopep695", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/autopep695/cli.py", line 76, in main
    analyzer.format_paths(args.paths, args.parallel)
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/autopep695/analyzer.py", line 114, in format_paths
    _format_dir(path)
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/autopep695/analyzer.py", line 54, in _format_dir
    _format_dir(p)
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/autopep695/analyzer.py", line 54, in _format_dir
    _format_dir(p)
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/autopep695/analyzer.py", line 54, in _format_dir
    _format_dir(p)
  [Previous line repeated 1 more time]
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/autopep695/analyzer.py", line 57, in _format_dir
    _format_file(p)
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/autopep695/analyzer.py", line 44, in _format_file
    code = format_code(f.read())
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/autopep695/analyzer.py", line 36, in format_code
    new_tree = tree.visit(transformer)
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/module.py", line 89, in visit
    result = super(Module, self).visit(visitor)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/module.py", line 74, in _visit_and_replace_children
    body=visit_body_sequence(self, "body", self.body, visitor),
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/internal.py", line 227, in visit_body_sequence
    return tuple(visit_body_iterable(parent, fieldname, children, visitor))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/internal.py", line 193, in visit_body_iterable
    new_child = child.visit(visitor)
                ^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/statement.py", line 1985, in _visit_and_replace_children
    body=visit_required(self, "body", self.body, visitor),
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/internal.py", line 81, in visit_required
    result = node.visit(visitor)
             ^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/statement.py", line 698, in _visit_and_replace_children
    body=visit_body_sequence(self, "body", self.body, visitor),
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/internal.py", line 227, in visit_body_sequence
    return tuple(visit_body_iterable(parent, fieldname, children, visitor))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/internal.py", line 193, in visit_body_iterable
    new_child = child.visit(visitor)
                ^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/statement.py", line 1814, in _visit_and_replace_children
    body=visit_required(self, "body", self.body, visitor),
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/internal.py", line 81, in visit_required
    result = node.visit(visitor)
             ^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/statement.py", line 698, in _visit_and_replace_children
    body=visit_body_sequence(self, "body", self.body, visitor),
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/internal.py", line 227, in visit_body_sequence
    return tuple(visit_body_iterable(parent, fieldname, children, visitor))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/internal.py", line 193, in visit_body_iterable
    new_child = child.visit(visitor)
                ^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/statement.py", line 616, in _visit_and_replace_children
    body=visit_required(self, "body", self.body, visitor),
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/internal.py", line 81, in visit_required
    result = node.visit(visitor)
             ^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/statement.py", line 495, in _visit_and_replace_children
    body=visit_sequence(self, "body", self.body, visitor),
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/internal.py", line 177, in visit_sequence
    return tuple(visit_iterable(parent, fieldname, children, visitor))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/internal.py", line 159, in visit_iterable
    new_child = child.visit(visitor)
                ^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_nodes/base.py", line 236, in visit
    leave_result = visitor.on_leave(self, with_updated_children)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/matchers/_visitors.py", line 515, in on_leave
    retval = CSTTransformer.on_leave(self, original_node, updated_node)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/_visitors.py", line 71, in on_leave
    updated_node = leave_func(original_node, updated_node)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/autopep695/format.py", line 13, in leave_Assign
    if self._should_ignore_statement(original_node):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/autopep695/base.py", line 300, in _should_ignore_statement
    parent = cst.ensure_type(self._node_to_parent[node], cst.SimpleStatementLine)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/libcst/helpers/common.py", line 22, in ensure_type
    raise Exception(
Exception: Expected a SimpleStatementLine but got a SimpleStatementSuite!

System info

autopep695 1.0.0 at /home/john/.cache/uv/archive-v0/GdS6bhQ7eIWjoTKEtP1qx/lib/python3.12/site-packages/autopep695
CPython 3.12.4 Clang 18.1.8 
Linux #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64

Further info

No response

Checklist

yowoda commented 1 week ago

Hey! Thanks for the bug report and apologies for the rather confusing error message. I will be pushing a fix later today that should improve error handling for internal errors and fix your issue altogether.

yowoda commented 1 week ago

I just pushed a fix, hopefully that works for you, if not please let me know. It won't be on PyPi until the next release (which should be tomorrow or in 2 days) so for now you will have to install from the master branch.

yowoda commented 2 days ago

Going to close this issue now, please re-open if you're still having problems.