Type the plugin and internal API surfaces - #4014
Open
gaborbernat wants to merge 2 commits into
Open
Conversation
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.
for more information, see https://pre-commit.ci
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 get typed APIs where tox handed them
Any, and the code base now passes three typecheckers: ty (the existing gate), mypy in strict mode, and pyrefly.
For plugin authors
conf.get("key", Type)returns a configuration value verified at runtime against its declared type, so plugins candrop the
castthey wrap aroundconf["key"]today. The untypedconf["key"]read stays as is.tox_on_installhook andInstaller.installreceiveInstallArguments, a named union of what tox installs(requirements file, pylock file, or a sequence of requirements and packages).
Installergrew a second typeparameter defaulting to that union, so existing
Installer[MyEnv]subclasses keep working.Parseddeclares the CLI option surface:options.recreateand friends complete in editors and type-check.add_configacceptsdefault=Nonefor optional values and infers the value type from callable defaults.JsonValuecontent; structuredset_enventriesmatch the new
SetEnvEntryshape; package modes and run modes areLiteraltypes.Guard rails
tox r -e typenow runs mypy (strict) and pyrefly after ty; all three pass, and each keeps its own command so tystays fast. Suppressions name the specific error code and the reason (usually an upstream stub gap or a checker
inference limit, e.g. wrong inference of function literals off subclass-of types astral-sh/ty#2428, which this change works around for six of its seven call sites).
tests/type_check/pins the inference behavior of the new APIs withassert_typefiles all three checkers read.typing-extensionsbecomes a runtime dependency below Python 3.13 to supplyTypeVardefaults.Fixes the stricter checks surfaced
intthroughout reporting, yet hold ANSI escape strings.pyproject.tomlwheretool.toxorenv_baseis not a table produced a traceback; both now report anerror (or fall back to other configuration sources during discovery).
{ product = ... }form accepted a non-listexclude; it now rejects it.Beyond those three, runtime behavior does not change.