🐛 fix(env): suggest normalized env name for dotted Python versions#3888
Merged
rahuldevikar merged 2 commits intotox-dev:mainfrom Mar 19, 2026
Merged
🐛 fix(env): suggest normalized env name for dotted Python versions#3888rahuldevikar merged 2 commits intotox-dev:mainfrom
rahuldevikar merged 2 commits intotox-dev:mainfrom
Conversation
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
for more information, see https://pre-commit.ci
rahuldevikar
approved these changes
Mar 19, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Users typing
tox -e py3.10-lintwhen their envlist definedpy310-lintsaw 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.10vspy310,3.10vs310. The validation logic treated dotted versions as valid dynamic factors even when a normalized equivalent existed in the config. 🔍 Sincepy3.10matched the Python version regex andlintwas a valid factor,py3.10-lintpassed 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.15when onlypy310andpy311are 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