diff --git a/src/python/pants/backend/python/lint/autoflake/rules.py b/src/python/pants/backend/python/lint/autoflake/rules.py index b7f08226d21..555d0bd13a0 100644 --- a/src/python/pants/backend/python/lint/autoflake/rules.py +++ b/src/python/pants/backend/python/lint/autoflake/rules.py @@ -47,7 +47,6 @@ async def autoflake_fmt(request: AutoflakeRequest, autoflake: Autoflake) -> FmtR autoflake_pex, argv=( "--in-place", - "--remove-all-unused-imports", *autoflake.args, *request.snapshot.files, ), diff --git a/src/python/pants/backend/python/lint/autoflake/subsystem.py b/src/python/pants/backend/python/lint/autoflake/subsystem.py index 88927791e92..c67d9e9d5c3 100644 --- a/src/python/pants/backend/python/lint/autoflake/subsystem.py +++ b/src/python/pants/backend/python/lint/autoflake/subsystem.py @@ -33,7 +33,13 @@ class Autoflake(PythonToolBase): default_lockfile_url = git_url(default_lockfile_path) skip = SkipOption("fmt", "lint") - args = ArgsListOption(example="--target-version=py37 --quiet") + args = ArgsListOption( + example="--remove-all-unused-imports --target-version=py37 --quiet", + # This argument was previously hardcoded. Moved it a default argument + # to allow it to be overridden while maintaining the existing api. + # See: https://github.com/pantsbuild/pants/issues/16193 + default=["--remove-all-unused-imports"], + ) export = ExportToolOption() diff --git a/src/python/pants/option/option_types.py b/src/python/pants/option/option_types.py index a5e790adbd2..8d5a7d82d4a 100644 --- a/src/python/pants/option/option_types.py +++ b/src/python/pants/option/option_types.py @@ -216,7 +216,7 @@ def __new__( cls, flag_name: str | None = None, *, - default: _MaybeDynamicT[list[_ListMemberT]] = [], + default: _MaybeDynamicT[list[_ListMemberT]] | None = [], help: _HelpT, # Additional bells/whistles register_if: _RegisterIfFuncT | None = None, @@ -789,6 +789,7 @@ def __new__( # This should be set when callers can alternatively use "--" followed by the arguments, # instead of having to provide "--[scope]-args='--arg1 --arg2'". passthrough: bool | None = None, + default: _MaybeDynamicT[list[_ListMemberT]] | None = None, ): if extra_help: extra_help = "\n\n" + extra_help @@ -802,6 +803,7 @@ def __new__( """ ) ), + default=default, # type: ignore[arg-type] ) if passthrough is not None: instance._extra_kwargs["passthrough"] = passthrough