Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on specific pattern #259

Open
scottkmaxwell opened this issue May 22, 2023 · 1 comment
Open

Crash on specific pattern #259

scottkmaxwell opened this issue May 22, 2023 · 1 comment
Labels

Comments

@scottkmaxwell
Copy link

Hi. I have a file that has this line:

from ci.zimbeast.test_scripts.framework.test_interrupt.seq_lib \
    import IntTestSequence, send_int

Autoflake crashes with:

File ".../python3.10/site-packages/autoflake.py", line 350, in __init__
self.from_, imports = self.IMPORT_RE.split(line, maxsplit=1)
ValueError: not enough values to unpack (expected 2, got 1)
@fsouza fsouza added the bug label May 29, 2023
@fsouza
Copy link
Collaborator

fsouza commented May 29, 2023

Basically, the multi-line support for imports can't really handle the import keyword being in a different line. Here's an easy way to reproduce this with the test suite:

diff --git a/test_autoflake.py b/test_autoflake.py
index 4dd6271..298015a 100755
--- a/test_autoflake.py
+++ b/test_autoflake.py
@@ -685,6 +685,9 @@ os.foo()
 from os.path import \
     isdir
 isdir('42')
+from os.path \
+    import samefile
+print(samefile('a', 'a'))
 """,
             "".join(
                 autoflake.filter_code(
@@ -704,6 +707,9 @@ from os.path import \
     isfile \
     , isdir
 isdir('42')
+from os.path \
+    import pardir, samefile
+print(samefile('a', 'a'))
 """,
                 ),
             ),

Personally, I feel like it would be a better idea to stop relying on regular expressions for this, but that's coming later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants