Skip to content

Commit c60aab8

Browse files
committed
Allow use of list[str] inside plugins
Fixes: #3287
1 parent 406f808 commit c60aab8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

docs/changelog/3288.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow ``ConfigSet.add_config`` to receive parameterized generics for ``of_type``.

src/tox/config/loader/convert.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import typing
34
from abc import ABC, abstractmethod
45
from collections import OrderedDict
56
from pathlib import Path
@@ -39,6 +40,15 @@ def to(self, raw: T, of_type: type[V], factory: Factory[V]) -> V: # noqa: PLR09
3940
return self.to_env_list(raw) # type: ignore[return-value]
4041
if issubclass(of_type, str):
4142
return self.to_str(raw) # type: ignore[return-value]
43+
# python does not allow use of parametrized generics with isinstance,
44+
# so we need to check for them.
45+
if (
46+
hasattr(typing, "GenericAlias")
47+
and isinstance(raw, typing.GenericAlias)
48+
and typing.get_args(of_type)
49+
and typing.get_args(of_type)[0] is str
50+
):
51+
return raw # type: ignore[no-any-return]
4252
if isinstance(raw, of_type): # already target type no need to transform it
4353
# do it this late to allow normalization - e.g. string strip
4454
return raw

0 commit comments

Comments
 (0)