Describe the bug
In unit tests, specifying the --target-version flag raises AttributeError: 'tuple' object has no attribute 'append'.
To Reproduce
Just add # flags: --target-version=py310 on top of any unit test and then run with tox -e py.
The resulting error is:
AttributeError: 'tuple' object has no attribute 'append'.
Expected behavior
The unit test should run successfully with target_versions set to exactly what was specified.
Environment
- Black's version:
main at bdd7fcd (latest as of now)
- OS and Python version: Ubuntu 24.04 LTS, Python 3.12 and Python 3.14 (checked on both)
Additional context
The error occurs due to this code:
parser.add_argument(
"--target-version",
action="append",
type=lambda val: TargetVersion[val.upper()],
default=(),
)
The issue arises because default is a tuple, but action="append" expects a list. When the flag is used, it attempts to call .append() on the tuple, leading to an AttributeError.
A possible fix is:
parser.add_argument(
"--target-version",
action="store",
type=lambda val: (TargetVersion[val.upper()],),
default=(),
)
Alternatively, setting default=[] would also work with action="append".
However, the original use of a tuple as the default was likely intentional.
Describe the bug
In unit tests, specifying the
--target-versionflag raisesAttributeError: 'tuple' object has no attribute 'append'.To Reproduce
Just add
# flags: --target-version=py310on top of any unit test and then run withtox -e py.The resulting error is:
Expected behavior
The unit test should run successfully with
target_versionsset to exactly what was specified.Environment
mainat bdd7fcd (latest as of now)Additional context
The error occurs due to this code:
A possible fix is: