Skip to content

Commit

Permalink
Update merge_configuration_file to prefer values from flags
Browse files Browse the repository at this point in the history
The idea is that options set with flags take precedence over options set
in the configuration file (any configuration file).
  • Loading branch information
fsouza committed Oct 9, 2022
1 parent f3534ba commit 5928483
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,8 +1245,9 @@ def merge_configuration_file(args):
name,
)
return False
if value:
setattr(args, name.replace("-", "_"), value)
arg = name.replace("-", "_")
if value and not hasattr(args, arg):
setattr(args, arg, value)
else:
_LOGGER.error("'%s' is not a valid configuration option", name)
return False
Expand Down
24 changes: 24 additions & 0 deletions test_autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -3430,6 +3430,30 @@ def test_merge_with_cli_set_list_property(self):
{"files": files, "imports": "my_lib,other_lib", "config_file": None},
)

def test_merge_doesnt_override_existing_attributes(self):
self.create_file("test_me.py")
self.create_file(
"pyproject.toml",
"[tool.autoflake]\ncheck = false\n",
)
files = [self.effective_path("test_me.py")]
args = Namespace(
files=files,
imports="other_lib",
config_file=None,
check=True,
)
assert autoflake.merge_configuration_file(args)
self.assert_namespace(
args,
{
"files": files,
"imports": "other_lib",
"config_file": None,
"check": True,
},
)


@contextlib.contextmanager
def temporary_file(contents, directory=".", suffix=".py", prefix=""):
Expand Down

0 comments on commit 5928483

Please sign in to comment.