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

Update merge_configuration_file to prefer values from flags #158

Merged
merged 1 commit into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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