autoflake icon indicating copy to clipboard operation
autoflake copied to clipboard

ValueError: not enough values to unpack (expected 2, got 1) in break_up_import

Open gabe-sherman opened this issue 8 months ago • 2 comments

The following call to fix_code fails with a ValueError: not enough values to unpack (expected 2, got 1) message. This occurs at line 533 in autoflake.py. The carriage return (\r) seems to be a necessary part of the input in order to trigger this.

import autoflake

s = '''
from t import (
\r  a,
    b,
)
from t import (
    a,
    b,
)
'''

autoflake.fix_code(s)

Setup Info

Version: 2.31 Commit: b87ff10c51f010a9de33f4cce54564cf232a75be

Trace Report

Traceback (most recent call last):
  File "rep.py", line 14, in <module>
    autoflake.fix_code(s)
  File "lib/python3.10/site-packages/autoflake.py", line 924, in fix_code
    "".join(
  File "lib/python3.10/site-packages/autoflake.py", line 622, in filter_code
    result = filter_unused_import(
  File "lib/python3.10/site-packages/autoflake.py", line 697, in filter_unused_import
    return break_up_import(line)
  File "lib/python3.10/site-packages/autoflake.py", line 533, in break_up_import
    (indentation, imports) = re.split(
ValueError: not enough values to unpack (expected 2, got 1)

gabe-sherman avatar May 04 '25 19:05 gabe-sherman

@gabe-sherman thanks for the detailed report!

fsouza avatar May 08 '25 17:05 fsouza

Instead of ValueError, what should autoflake return in this situation? I will try to solve and make contribution. @fsouza @gabe-sherman

venturero avatar Jun 01 '25 13:06 venturero