Skip to content

Commit c8c9dbc

Browse files
authored
Fix add_config factory argument type annotation bad for containers (#2323)
1 parent cfe9463 commit c8c9dbc

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

docs/changelog/2233.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix type annotation is broken for :meth:`tox.config.sets.ConfigSet.add_config` when adding a container type
2+
- by :user:`gaborbernat`.

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ fail_under = 95
103103
omit =
104104
src/tox/config/cli/for_docs.py
105105
tests/execute/local_subprocess/bad_process.py
106+
tests/type_check/*
106107

107108
[coverage:paths]
108109
source =

src/tox/config/sets.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def add_config(
4545
default: Callable[[Config, str | None], V] | V,
4646
desc: str,
4747
post_process: Callable[[V], V] | None = None,
48-
factory: Factory[V] = None,
48+
factory: Factory[Any] = None,
4949
) -> ConfigDynamicDefinition[V]:
5050
"""
5151
Add configuration value.
@@ -55,7 +55,8 @@ def add_config(
5555
:param default: the default value of the config value
5656
:param desc: a help message describing the configuration
5757
:param post_process: a callback to post-process the configuration value after it has been loaded
58-
:param factory: factory method to use to build the object
58+
:param factory: factory method used to build contained objects (if ``of_type`` is a container type it
59+
should perform the contained item creation, otherwise creates objects that match the type)
5960
:return: the new dynamic config definition
6061
"""
6162
if self._final:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""check that factory for a container works"""
2+
from __future__ import annotations
3+
4+
from typing import List
5+
6+
from tox.config.sets import ConfigSet
7+
8+
9+
class EnvDockerConfigSet(ConfigSet):
10+
def register_config(self) -> None:
11+
def factory(container_name: object) -> str: # noqa: U100
12+
...
13+
14+
self.add_config(
15+
keys=["k"],
16+
of_type=List[str],
17+
default=[],
18+
desc="desc",
19+
factory=factory,
20+
)

0 commit comments

Comments
 (0)