Skip to content

Commit

Permalink
Fix default value for --imports
Browse files Browse the repository at this point in the history
This was generating a list with the empty string, which caused it to
match any import as a glob.

Closes #169.
  • Loading branch information
fsouza committed Oct 12, 2022
1 parent 6fdd34b commit dcc9b86
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ def _fix_file(

filtered_source = fix_code(
source,
additional_imports=args.get("imports", "").split(","),
additional_imports=(args["imports"].split(",") if "imports" in args else None),
expand_star_imports=args["expand_star_imports"],
remove_all_unused_imports=args["remove_all_unused_imports"],
remove_duplicate_keys=args["remove_duplicate_keys"],
Expand Down
20 changes: 20 additions & 0 deletions test_autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -2638,6 +2638,26 @@ def test_end_to_end_from_stdin_with_in_place(self):
"\n".join(stdout.decode().split(os.linesep)),
)

def test_end_to_end_dont_remove_unused_imports_when_not_using_flag(self):
with temporary_file(
"""\
from . import fake_bar
from . import fake_foo
fake_foo.fake_function()
""",
) as filename:
process = subprocess.Popen(
AUTOFLAKE_COMMAND
+ [
filename,
],
stdout=subprocess.PIPE,
)
self.assertEqual(
"",
"\n".join(process.communicate()[0].decode().split(os.linesep)[3:]),
)


class MultilineFromImportTests(unittest.TestCase):
def test_is_over(self):
Expand Down

0 comments on commit dcc9b86

Please sign in to comment.