Skip to content

Report an empty TOML command value as a handled error - #4041

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
dylanpulver:fix/toml-empty-scalar-command
Aug 25, 2026
Merged

Report an empty TOML command value as a handled error#4041
gaborbernat merged 1 commit into
tox-dev:mainfrom
dylanpulver:fix/toml-empty-scalar-command

Conversation

@dylanpulver

@dylanpulver dylanpulver commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

install_command = [] in TOML raises AttributeError: 'NoneType' object has no attribute 'args' with a traceback and exit code 2. list_dependencies_command = [] does the same. The ini spelling install_command= reports unable to determine pip install command: attempting to parse '' into a command failed and exits 1.

The cause

Convert.to_command is declared Command | None, and the two loaders disagree on what None means. StrConvert.to_command("") raises ValueError; TomlLoader.to_command([]) returns None, which is what lets #3388 drop empty entries inside commands. For a scalar of_type=Command that None is cast straight through to the caller, which then dereferences it.

The fix

to_command now returns a Command or raises, in every loader. The TOML rule that an empty entry inside a list of commands is dropped moves into TomlLoader.to_list, which is where StrConvert.to_list already drops empty tokens. convert.py loses its Command-shaped branch in the shared list path, so the format-specific rule no longer leaks into the format-agnostic layer.

Making the abstract return type Command also surfaced that StrConvert.to_command never returned None in the first place - ty rejected the override until the annotation was corrected.

Both formats now stop before the dereference:

$ printf '[env.py]\ninstall_command = []\n' > tox.toml && tox r -e py
py: failed to load py.install_command: attempting to parse [] into a command failed

Drive-by: TomlLoader.to_set was a byte-for-byte copy of to_list and now delegates to it.

Verification

test_toml_loader_command_empty_nok covers the scalar rejection and test_toml_loader_command_list_drops_empty pins the #3388 behaviour; removing either half of the change fails the matching test. test_pip_toml_empty_command_error is parametrised over install_command and list_dependencies_command, the two scalar Command settings.

Full suite passes, as do tox -e type (ty, mypy, pyrefly) and tox -e fix.

  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

@gaborbernat
gaborbernat force-pushed the fix/toml-empty-scalar-command branch from ac4e877 to 9595a43 Compare August 25, 2026 03:59
@gaborbernat gaborbernat changed the title Report an empty install_command in TOML as a handled error Report an empty TOML command value as a handled error Aug 25, 2026
@gaborbernat
gaborbernat enabled auto-merge (squash) August 25, 2026 04:08
@gaborbernat
gaborbernat merged commit 59e984f into tox-dev:main Aug 25, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants