-
-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python 3.13 test failure: tests/config/loader/test_str_convert.py::test_str_convert_ok_py39[1,2-value1-Optional] - TypeError: issubclass() arg 1 must be a class
#3290
Comments
This ugly diff makes it work: diff --git a/src/tox/config/loader/convert.py b/src/tox/config/loader/convert.py
index 9379c6ea..66ad266d 100644
--- a/src/tox/config/loader/convert.py
+++ b/src/tox/config/loader/convert.py
@@ -30,6 +30,10 @@ class Convert(ABC, Generic[T]):
from_module = getattr(of_type, "__module__", None)
if from_module in {"typing", "typing_extensions"}:
return self._to_typing(raw, of_type, factory)
+ # python does not allow use of parametrized generics with isinstance,
+ # so we need to check for them.
+ if hasattr(typing, "GenericAlias") and isinstance(of_type, typing.GenericAlias):
+ return list(self.to_list(raw, of_type=of_type)) # type: ignore[return-value]
if issubclass(of_type, Path):
return self.to_path(raw) # type: ignore[return-value]
if issubclass(of_type, bool):
@@ -40,10 +44,6 @@ class Convert(ABC, Generic[T]):
return self.to_env_list(raw) # type: ignore[return-value]
if issubclass(of_type, str):
return self.to_str(raw) # type: ignore[return-value]
- # python does not allow use of parametrized generics with isinstance,
- # so we need to check for them.
- if hasattr(typing, "GenericAlias") and isinstance(of_type, typing.GenericAlias):
- return list(self.to_list(raw, of_type=of_type)) # type: ignore[return-value]
if isinstance(raw, of_type): # already target type no need to transform it
# do it this late to allow normalization - e.g. string strip
return raw
diff --git a/src/tox/config/loader/str_convert.py b/src/tox/config/loader/str_convert.py
index 63fc41de..f2888a13 100644
--- a/src/tox/config/loader/str_convert.py
+++ b/src/tox/config/loader/str_convert.py
@@ -6,6 +6,7 @@ import shlex
import sys
from itertools import chain
from pathlib import Path
+import typing
from typing import TYPE_CHECKING, Any, Iterator
from tox.config.loader.convert import Convert
@@ -28,7 +29,7 @@ class StrConvert(Convert[str]):
@staticmethod
def to_list(value: str, of_type: type[Any]) -> Iterator[str]:
- splitter = "\n" if issubclass(of_type, Command) or "\n" in value else ","
+ splitter = "\n" if (not isinstance(of_type, getattr(typing, "GenericAlias", type(None))) and issubclass(of_type, Command)) or "\n" in value else ","
splitter = splitter.replace("\r", "")
for token in value.split(splitter):
value = token.strip() It makes sure that:
The change in str_convert could probably be split into a function of its own. |
I'd submit a PR, but I wonder where else this is used, possibly not covered by tests? |
Also, if I need a |
Up to you 👍 I would keep it private and close to where it is used. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue
When running the test suite on Python 3.13.0b1, I'm getting the following test failure:
Apparently, this is intentional change: python/cpython#101162
Environment
Provide at least:
Output of running tox
n/a
Minimal example
n/a
The text was updated successfully, but these errors were encountered: