Repository navigation
✨ feat(plugin): type the plugin and internal API surfaces - #4014
Merged
Merged
Conversation
gaborbernat
force-pushed
the
typed-api
branch
4 times, most recently
from
August 9, 2026 16:23
e787498 to
6e24409
Compare
gaborbernat
force-pushed
the
typed-api
branch
7 times, most recently
from
August 9, 2026 20:02
4cba309 to
00ced99
Compare
Replace Any on the surfaces plugins build against: * ConfigSet.get(key, of_type) reads a config value verified against its declared type, replacing cast() around conf["key"] reads * tox_on_install and Installer type arguments as InstallArguments; a second Installer type parameter (defaulting to that union) lets subclasses narrow it while Installer[Env] keeps working * Parsed declares the CLI option surface so options.<name> type-checks * add_config accepts default=None, infers value types from callable defaults, and drops six of the seven ty overload suppressions * journal, env cache, and execute metadata content is JsonValue; structured set_env entries match SetEnvEntry; package modes, run modes, and the replacer dispatch use Literal types The type env now gates mypy --strict and pyrefly next to ty; all three pass. typing-extensions becomes a runtime dependency below Python 3.13 for TypeVar defaults. The stricter checks surfaced two fixes: colorama colors were annotated int yet hold strings, and a non-table tool.tox or env_base in pyproject.toml no longer crashes.
2 tasks
rockygeekz
added a commit
to ansible/tox-ansible
that referenced
this pull request
Aug 11, 2026
* fix(tests): add result_json to Parsed() calls for tox 4.59 compat tox 4.59.0 (tox-dev/tox#4014) changed State.__init__ to access options.parsed.result_json directly instead of using getattr with a fallback default. This breaks tests that construct Parsed objects without including result_json, causing AttributeError in 28 tests. Adding result_json=None to all Parsed() constructor calls in the test suite fixes the devel test failures. * style: wrap long Parsed() calls to satisfy line length limit * refactor(tests): extract _parsed helper to reduce test_plugin line count Replace 26 verbose multi-line Parsed() calls with a compact _parsed() helper that sets default override=[] and result_json=None. Brings the module from 1644 lines back under the 1600 pylint limit.
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.
Plugin authors work against surfaces tox types as
Any: everyconf["key"]read needs acast, thetox_on_installhook gives no clue whatargumentsholds, and a typo inoptions.<name>only surfaces at runtime. 🧩 This change types those surfaces so editors complete them and type checkers verify them, for plugins and for tox itself.ConfigSet.get(key, of_type)returns a configuration value verified at runtime against its declared type, while theAny-returningconf["key"]stays for compatibility. Thetox_on_installhook andInstaller.installreceiveInstallArguments, a named union of what tox installs;Installergained a second type parameter that defaults to this union, so existingInstaller[MyEnv]subclasses keep working.Parseddeclares the CLI option surface,add_configacceptsdefault=Noneand infers value types from callable defaults (removing six of the seven suppressions for astral-sh/ty#2428), persisted JSON documents share aJsonValuealias, and package plus run modes becameLiteraltypes. ✨ To keep this true over time, thetypeenvironment now runsmypyin strict mode andpyreflyafterty, each as its own command sotykeeps finishing in under a second, andtests/type_check/pins the inference behavior of the new APIs under all three checkers.The added checkers caught three bugs: reporting annotated colorama colors as
intalthough they hold ANSI escape strings, apyproject.tomlwith a non-tabletool.toxorenv_baseraised a traceback instead of an error, and the structured{ product = ... }form accepted a non-listexclude. 🐛 Beyond those, runtime behavior does not change;typing-extensionsbecomes a runtime dependency below Python 3.13 to supplyTypeVardefaults, and each remaining suppression names its error code and the upstream gap it works around.