Bug 2353145 - python-tox fails to build with Python 3.14: test_str_convert_nok: AssertionError: Regex pattern did not match. Regex: '3 cannot cast to typing.Union\\[str, int\\]' vs Input: '3 cannot cast to str | int'
Summary: python-tox fails to build with Python 3.14: test_str_convert_nok: AssertionE...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: python-tox
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Miro Hrončok
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: PYTHON3.14
TreeView+ depends on / blocked
 
Reported: 2025-03-18 11:26 UTC by Karolina Surma
Modified: 2025-03-28 13:18 UTC (History)
5 users (show)

Fixed In Version: python-tox-4.25.0-2.fc43
Clone Of:
Environment:
Last Closed: 2025-03-18 12:13:07 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Fedora Package Sources python-tox pull-request 173 0 None None None 2025-03-18 12:06:18 UTC
Github tox-dev tox pull 3500 0 None open Tests: Adjust expected exception message for Python 3.14.0a6 2025-03-18 11:59:30 UTC

Description Karolina Surma 2025-03-18 11:26:37 UTC
python-tox fails to build with Python 3.14.0a6.

_ test_str_convert_nok[3-Union-TypeError-3 cannot cast to typing.Union\\[str, int\\]] _
[gw0] linux -- Python 3.14.0 /usr/bin/python3

raw = '3', of_type = str | int
msg = '3 cannot cast to typing.Union\\[str, int\\]'
exc_type = <class 'TypeError'>

    @pytest.mark.parametrize(
        ("raw", "of_type", "exc_type", "msg"),
        [
            ("a", TypeVar, TypeError, r"a cannot cast to .*typing.TypeVar.*"),
            ("3", Literal["1", "2"], ValueError, r"3 must be one of \('1', '2'\)"),
            ("3", Union[str, int], TypeError, r"3 cannot cast to typing.Union\[str, int\]"),
            ("", Command, ValueError, r"attempting to parse '' into a command failed"),
        ],
    )
    def test_str_convert_nok(raw: str, of_type: type[Any], msg: str, exc_type: type[Exception]) -> None:
        with pytest.raises(exc_type, match=msg):
>           StrConvert().to(raw, of_type, None)

exc_type   = <class 'TypeError'>
msg        = '3 cannot cast to typing.Union\\[str, int\\]'
of_type    = str | int
raw        = '3'

tests/config/loader/test_str_convert.py:86: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../BUILDROOT/usr/lib/python3.14/site-packages/tox/config/loader/convert.py:33: in to
    return self._to_typing(raw, of_type, factory)
        factory    = None
        from_module = 'typing'
        of_type    = str | int
        raw        = '3'
        self       = <tox.config.loader.str_convert.StrConvert object at 0x7f2515eb1a90>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <tox.config.loader.str_convert.StrConvert object at 0x7f2515eb1a90>
raw = '3', of_type = str | int, factory = None

    def _to_typing(self, raw: T, of_type: type[V], factory: Factory[V]) -> V:  # noqa: C901
        origin = getattr(of_type, "__origin__", of_type.__class__)
        result: Any = _NO_MAPPING
        if origin in {list, List}:
            entry_type = of_type.__args__[0]  # type: ignore[attr-defined]
            result = [self.to(i, entry_type, factory) for i in self.to_list(raw, entry_type)]
            if isclass(entry_type) and issubclass(entry_type, Command):
                result = [i for i in result if i is not None]
        elif origin in {set, Set}:
            entry_type = of_type.__args__[0]  # type: ignore[attr-defined]
            result = {self.to(i, entry_type, factory) for i in self.to_set(raw, entry_type)}
        elif origin in {dict, Dict}:
            key_type, value_type = of_type.__args__[0], of_type.__args__[1]  # type: ignore[attr-defined]
            result = OrderedDict(
                (self.to(k, key_type, factory), self.to(v, value_type, factory))
                for k, v in self.to_dict(raw, (key_type, value_type))
            )
        elif origin == Union:  # handle Optional values
            args: list[type[Any]] = of_type.__args__  # type: ignore[attr-defined]
            none = type(None)
            if len(args) == 2 and none in args:  # noqa: PLR2004
                if isinstance(raw, str):
                    raw = raw.strip()  # type: ignore[assignment]
                if not raw:
                    result = None
                else:
                    new_type = next(i for i in args if i != none)  # pragma: no cover
                    result = self.to(raw, new_type, factory)
        elif origin in {Literal, type(Literal)}:
            choice = of_type.__args__  # type: ignore[attr-defined]
            if raw not in choice:
                msg = f"{raw} must be one of {choice}"
                raise ValueError(msg)
            result = raw
        if result is not _NO_MAPPING:
            return cast("V", result)
        msg = f"{raw} cannot cast to {of_type!r}"
>       raise TypeError(msg)
E       TypeError: 3 cannot cast to str | int

args       = (<class 'str'>, <class 'int'>)
factory    = None
msg        = '3 cannot cast to str | int'
none       = <class 'NoneType'>
of_type    = str | int
origin     = <class 'typing.Union'>
raw        = '3'
result     = <object object at 0x7f251d779830>
self       = <tox.config.loader.str_convert.StrConvert object at 0x7f2515eb1a90>

../BUILDROOT/usr/lib/python3.14/site-packages/tox/config/loader/convert.py:92: TypeError

During handling of the above exception, another exception occurred:

raw = '3', of_type = str | int
msg = '3 cannot cast to typing.Union\\[str, int\\]'
exc_type = <class 'TypeError'>

    @pytest.mark.parametrize(
        ("raw", "of_type", "exc_type", "msg"),
        [
            ("a", TypeVar, TypeError, r"a cannot cast to .*typing.TypeVar.*"),
            ("3", Literal["1", "2"], ValueError, r"3 must be one of \('1', '2'\)"),
            ("3", Union[str, int], TypeError, r"3 cannot cast to typing.Union\[str, int\]"),
            ("", Command, ValueError, r"attempting to parse '' into a command failed"),
        ],
    )
    def test_str_convert_nok(raw: str, of_type: type[Any], msg: str, exc_type: type[Exception]) -> None:
>       with pytest.raises(exc_type, match=msg):
E       AssertionError: Regex pattern did not match.
E        Regex: '3 cannot cast to typing.Union\\[str, int\\]'
E        Input: '3 cannot cast to str | int'

exc_type   = <class 'TypeError'>
msg        = '3 cannot cast to typing.Union\\[str, int\\]'
of_type    = str | int
raw        = '3'

https://docs.python.org/3.14/whatsnew/3.14.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.14/fedora-rawhide-x86_64/08783548-python-tox/

For all our attempts to build python-tox with Python 3.14, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.14/package/python-tox/

Testing and mass rebuild of packages is happening in copr.
You can follow these instructions to test locally in mock if your package builds with Python 3.14:
https://copr.fedorainfracloud.org/coprs/g/python/python3.14/

Let us know here if you have any questions.

Python 3.14 is planned to be included in Fedora 43.
To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.14.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires),
so if this package is required a lot, it's important for us to get it fixed soon.

We'd appreciate help from the people who know this package best,
but if you don't want to work on this now, let us know so we can try to work around it on our side.

Comment 1 Miro Hrončok 2025-03-18 11:59:30 UTC
Fix proposed upstream in https://github.com/tox-dev/tox/pull/3500

Comment 3 Fedora Update System 2025-03-28 13:13:44 UTC
FEDORA-2025-d2222deddf (python-tox-4.25.0-2.fc43) has been submitted as an update to Fedora 43.
https://bodhi.fedoraproject.org/updates/FEDORA-2025-d2222deddf

Comment 4 Fedora Update System 2025-03-28 13:18:52 UTC
FEDORA-2025-d2222deddf (python-tox-4.25.0-2.fc43) has been pushed to the Fedora 43 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.