Skip to content

🐛 fix(env): suggest normalized env name for dotted Python versions#3888

Merged
rahuldevikar merged 2 commits intotox-dev:mainfrom
gaborbernat:3877
Mar 19, 2026
Merged

🐛 fix(env): suggest normalized env name for dotted Python versions#3888
rahuldevikar merged 2 commits intotox-dev:mainfrom
gaborbernat:3877

Conversation

@gaborbernat
Copy link
Copy Markdown
Member

Users typing tox -e py3.10-lint when their envlist defined py310-lint saw the command silently fall back to the base [testenv] configuration, running the wrong environment without warning or error. This became increasingly problematic with Python 3.10+ where dotted version notation (py3.10, py3.11) is common, creating easy-to-miss typos that produce confusing results.

Python version factors can be written with or without dots: py3.10 vs py310, 3.10 vs 310. The validation logic treated dotted versions as valid dynamic factors even when a normalized equivalent existed in the config. 🔍 Since py3.10 matched the Python version regex and lint was a valid factor, py3.10-lint passed validation and created an ad-hoc environment using [testenv] instead of the intended [testenv:py310-lint].

The fix normalizes environment names by removing dots from Python version factors, then checks if the normalized name exists in known environments. When found, tox errors with py3.10-lint - did you mean py310-lint? instead of silently proceeding. ✨ If the normalized name doesn't exist (e.g., py3.15 when only py310 and py311 are defined), the dotted version is allowed as an ad-hoc environment, preserving the flexibility of tox's dynamic environment creation.

This catches typos while maintaining backward compatibility for intentional ad-hoc environments.

Fixes #3877

@gaborbernat gaborbernat added the bug:normal affects many people or has quite an impact label Mar 19, 2026
@gaborbernat gaborbernat marked this pull request as draft March 19, 2026 00:51
Users typing `tox -e py3.10-lint` when `py310-lint` was defined in envlist
saw the command silently fall back to the base `[testenv]` configuration,
running the wrong environment without any warning. This happened because
Python versions can be written with or without dots (py3.10 vs py310), and
the validation logic treated dotted versions as valid factors even when a
normalized equivalent existed.

The fix normalizes environment names by removing dots from Python version
factors before checking if the normalized name exists in known environments.
When a match is found, tox now errors with a clear suggestion instead of
silently falling back. For example, `py3.10-lint` suggests `py310-lint` if
that environment exists. If the normalized name doesn't exist, the dotted
version is allowed as an ad-hoc environment (preserving existing behavior).

Fixes tox-dev#3877
@gaborbernat gaborbernat marked this pull request as ready for review March 19, 2026 01:46
@rahuldevikar rahuldevikar merged commit a438b58 into tox-dev:main Mar 19, 2026
27 checks passed
@gaborbernat gaborbernat deleted the 3877 branch March 19, 2026 01:55
gaborbernat added a commit to gaborbernat/tox that referenced this pull request Mar 30, 2026
…ox-dev#3888)

Users typing `tox -e py3.10-lint` when their envlist defined
`py310-lint` saw the command silently fall back to the base `[testenv]`
configuration, running the wrong environment without warning or error.
This became increasingly problematic with Python 3.10+ where dotted
version notation (py3.10, py3.11) is common, creating easy-to-miss typos
that produce confusing results.

Python version factors can be written with or without dots: `py3.10` vs
`py310`, `3.10` vs `310`. The validation logic treated dotted versions
as valid dynamic factors even when a normalized equivalent existed in
the config. 🔍 Since `py3.10` matched the Python version regex and `lint`
was a valid factor, `py3.10-lint` passed validation and created an
ad-hoc environment using `[testenv]` instead of the intended
`[testenv:py310-lint]`.

The fix normalizes environment names by removing dots from Python
version factors, then checks if the normalized name exists in known
environments. When found, tox errors with `py3.10-lint - did you mean
py310-lint?` instead of silently proceeding. ✨ If the normalized name
doesn't exist (e.g., `py3.15` when only `py310` and `py311` are
defined), the dotted version is allowed as an ad-hoc environment,
preserving the flexibility of tox's dynamic environment creation.

This catches typos while maintaining backward compatibility for
intentional ad-hoc environments.

Fixes tox-dev#3877

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided bug:normal affects many people or has quite an impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dot notation increases opportunities for environment factor mismatches and makes them harder to spot

2 participants