Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-typeguard for openSUSE:Factory checked in at 2025-06-30 13:03:35 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-typeguard (Old) and /work/SRC/openSUSE:Factory/.python-typeguard.new.7067 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-typeguard" Mon Jun 30 13:03:35 2025 rev:10 rq:1288852 version:4.4.4 Changes: -------- --- /work/SRC/openSUSE:Factory/python-typeguard/python-typeguard.changes 2025-03-06 14:48:35.341088108 +0100 +++ /work/SRC/openSUSE:Factory/.python-typeguard.new.7067/python-typeguard.changes 2025-06-30 13:03:47.915198736 +0200 @@ -1,0 +2,14 @@ +Wed Jun 25 14:16:58 UTC 2025 - John Paul Adrian Glaubitz <adrian.glaub...@suse.com> + +- Update to 4.4.4 + * Fixed IndexError when using @typechecked on more than one + function with the same name under certain circumstances (#527) + * Fixed TypeError during type checking when the value to check + is a parametrized generic class (#526) +- from version 4.4.3 + * Fixed @typechecked unable to find the target function or method if + it or the containing class had PEP 695 type parameters on them (#500) + * Fixed handling of union types on Python 3.14 (#522) + * Fixed __type_params__ getting lost when a function is instrumented + +------------------------------------------------------------------- Old: ---- typeguard-4.4.2-gh.tar.gz New: ---- typeguard-4.4.4-gh.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-typeguard.spec ++++++ --- /var/tmp/diff_new_pack.GhTvto/_old 2025-06-30 13:03:50.891322771 +0200 +++ /var/tmp/diff_new_pack.GhTvto/_new 2025-06-30 13:03:50.899323104 +0200 @@ -18,7 +18,7 @@ %{?sle15_python_module_pythons} Name: python-typeguard -Version: 4.4.2 +Version: 4.4.4 Release: 0 Summary: Library for runtime checking of Python types License: MIT ++++++ typeguard-4.4.2-gh.tar.gz -> typeguard-4.4.4-gh.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/.github/workflows/test.yml new/typeguard-4.4.4/.github/workflows/test.yml --- old/typeguard-4.4.2/.github/workflows/test.yml 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/.github/workflows/test.yml 2025-06-18 11:54:49.000000000 +0200 @@ -10,7 +10,7 @@ strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", pypy-3.10] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", pypy-3.11] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -21,8 +21,10 @@ allow-prereleases: true cache: pip cache-dependency-path: pyproject.toml - - name: Install dependencies - run: pip install -e .[test] + - name: Ensure pip >= v25.1 + run: python -m pip install "pip >= 25.1" + - name: Install the project and its dependencies + run: pip install --group test -e . - name: Test with pytest run: coverage run -m pytest - name: Upload Coverage diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/.pre-commit-config.yaml new/typeguard-4.4.4/.pre-commit-config.yaml --- old/typeguard-4.4.2/.pre-commit-config.yaml 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/.pre-commit-config.yaml 2025-06-18 11:54:49.000000000 +0200 @@ -14,14 +14,14 @@ - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.6 + rev: v0.11.4 hooks: - id: ruff args: [--fix, --show-fixes] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.14.1 + rev: v1.15.0 hooks: - id: mypy additional_dependencies: [ "typing_extensions" ] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/.readthedocs.yml new/typeguard-4.4.4/.readthedocs.yml --- old/typeguard-4.4.2/.readthedocs.yml 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/.readthedocs.yml 2025-06-18 11:54:49.000000000 +0200 @@ -4,13 +4,11 @@ os: ubuntu-22.04 tools: python: "3.11" + jobs: + install: + - python -m pip install --no-cache-dir "pip >= 25.1" + - python -m pip install --upgrade --upgrade-strategy only-if-needed --no-cache-dir --group doc . sphinx: configuration: docs/conf.py fail_on_warning: true - -python: - install: - - method: pip - path: . - extra_requirements: [doc] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/docs/versionhistory.rst new/typeguard-4.4.4/docs/versionhistory.rst --- old/typeguard-4.4.2/docs/versionhistory.rst 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/docs/versionhistory.rst 2025-06-18 11:54:49.000000000 +0200 @@ -4,6 +4,24 @@ This library adheres to `Semantic Versioning 2.0 <https://semver.org/#semantic-versioning-200>`_. +**4.4.4** (2026-06-18) + +- Fixed ``IndexError`` when using ``@typechecked`` on more than one function with the + same name under certain circumstances + (`#527 <https://github.com/agronholm/typeguard/issues/527>`_) +- Fixed ``TypeError`` during type checking when the value to check is a parametrized + generic class + (`#526 <https://github.com/agronholm/typeguard/issues/526>`_) + +**4.4.3** (2025-06-05) + +- Fixed ``@typechecked`` unable to find the target function or method if it or the + containing class had PEP 695 type parameters on them + (`#500 <https://github.com/agronholm/typeguard/issues/500>`_) +- Fixed handling of union types on Python 3.14 + (`#522 <https://github.com/agronholm/typeguard/issues/522>`_) +- Fixed ``__type_params__`` getting lost when a function is instrumented + **4.4.2** (2025-02-16) - Fixed ``TypeCheckError`` in unpacking assignment involving properties of a parameter diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/pyproject.toml new/typeguard-4.4.4/pyproject.toml --- old/typeguard-4.4.2/pyproject.toml 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/pyproject.toml 2025-06-18 11:54:49.000000000 +0200 @@ -1,6 +1,6 @@ [build-system] requires = [ - "setuptools >= 64", + "setuptools >= 77", "setuptools_scm[toml] >= 6.4" ] build-backend = "setuptools.build_meta" @@ -10,11 +10,10 @@ description = "Run-time type checker for Python" readme = "README.rst" authors = [{name = "Alex Grönholm", email = "alex.gronh...@nextday.fi"}] -license = {text = "MIT"} +license = "MIT" classifiers = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.9", @@ -27,7 +26,7 @@ requires-python = ">= 3.9" dependencies = [ "importlib_metadata >= 3.6; python_version < '3.10'", - "typing_extensions >= 4.10.0", + "typing_extensions >= 4.14.0", ] dynamic = ["version"] @@ -37,7 +36,10 @@ "Source code" = "https://github.com/agronholm/typeguard" "Issue tracker" = "https://github.com/agronholm/typeguard/issues" -[project.optional-dependencies] +[project.entry-points] +pytest11 = {typeguard = "typeguard._pytest_plugin"} + +[dependency-groups] test = [ "coverage[toml] >= 7", "pytest >= 7", @@ -50,9 +52,6 @@ "sphinx-rtd-theme >= 1.3.0", ] -[project.entry-points] -pytest11 = {typeguard = "typeguard._pytest_plugin"} - [tool.setuptools.package-data] typeguard = ["py.typed"] @@ -102,13 +101,14 @@ [tool.tox] env_list = ["py39", "py310", "py311", "py312", "py313", "py314"] skip_missing_interpreters = true +requires = ["tox >= 4.22"] [tool.tox.env_run_base] commands = [["coverage", "run", "-m", "pytest", { replace = "posargs", extend = true }]] package = "editable" -extras = ["test"] +dependency_groups = ["test"] [tool.tox.env.docs] depends = [] -extras = ["doc"] +dependency_groups = ["doc"] commands = [["sphinx-build", "-W", "-n", "docs", "build/sphinx"]] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/src/typeguard/_checkers.py new/typeguard-4.4.4/src/typeguard/_checkers.py --- old/typeguard-4.4.2/src/typeguard/_checkers.py 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/src/typeguard/_checkers.py 2025-06-18 11:54:49.000000000 +0200 @@ -172,7 +172,7 @@ if unfulfilled_kwonlyargs: raise TypeCheckError( f"has mandatory keyword-only arguments in its declaration: " - f'{", ".join(unfulfilled_kwonlyargs)}' + f"{', '.join(unfulfilled_kwonlyargs)}" ) num_positional_args = num_mandatory_pos_args = 0 @@ -500,8 +500,17 @@ ) finally: del errors # avoid creating ref cycle - elif not issubclass(value, expected_class): # type: ignore[arg-type] - raise TypeCheckError(f"is not a subclass of {qualified_name(expected_class)}") + else: + if isinstance(expected_class, generic_alias_types): + expected_class = get_origin(expected_class) + + if isinstance(value, generic_alias_types): + value = get_origin(value) + + if not issubclass(value, expected_class): + raise TypeCheckError( + f"is not a subclass of {qualified_name(expected_class)}" + ) def check_newtype( @@ -550,7 +559,7 @@ get_type_name(constraint) for constraint in origin_type.__constraints__ ) raise TypeCheckError( - f"does not match any of the constraints " f"({formatted_constraints})" + f"does not match any of the constraints ({formatted_constraints})" ) @@ -1041,7 +1050,7 @@ and getattr(origin_type, "__qualname__", "").startswith("NewType.") and hasattr(origin_type, "__supertype__") ): - # typing.NewType on Python 3.9 and below + # typing.NewType on Python 3.9 return check_newtype return None @@ -1066,7 +1075,7 @@ plugin = ep.load() except Exception as exc: warnings.warn( - f"Failed to load plugin {ep.name!r}: " f"{qualified_name(exc)}: {exc}", + f"Failed to load plugin {ep.name!r}: {qualified_name(exc)}: {exc}", stacklevel=2, ) continue diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/src/typeguard/_config.py new/typeguard-4.4.4/src/typeguard/_config.py --- old/typeguard-4.4.2/src/typeguard/_config.py 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/src/typeguard/_config.py 2025-06-18 11:54:49.000000000 +0200 @@ -92,8 +92,6 @@ If set to ``True``, the code of modules or functions instrumented by typeguard is printed to ``sys.stderr`` after the instrumentation is done - Requires Python 3.9 or newer. - Default: ``False`` """ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/src/typeguard/_decorators.py new/typeguard-4.4.4/src/typeguard/_decorators.py --- old/typeguard-4.4.2/src/typeguard/_decorators.py 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/src/typeguard/_decorators.py 2025-06-18 11:54:49.000000000 +0200 @@ -36,18 +36,19 @@ def find_target_function( new_code: CodeType, target_path: Sequence[str], firstlineno: int ) -> CodeType | None: - target_name = target_path[0] for const in new_code.co_consts: if isinstance(const, CodeType): - if const.co_name == target_name: + new_path = ( + target_path[1:] if const.co_name == target_path[0] else target_path + ) + if not new_path: if const.co_firstlineno == firstlineno: return const - elif len(target_path) > 1: - target_code = find_target_function( - const, target_path[1:], firstlineno - ) - if target_code: - return target_code + + continue + + if target_code := find_target_function(const, new_path, firstlineno): + return target_code return None @@ -117,13 +118,18 @@ new_function.__module__ = f.__module__ new_function.__name__ = f.__name__ new_function.__qualname__ = f.__qualname__ + new_function.__doc__ = f.__doc__ + new_function.__defaults__ = f.__defaults__ + new_function.__kwdefaults__ = f.__kwdefaults__ + + if sys.version_info >= (3, 12): + new_function.__type_params__ = f.__type_params__ + if sys.version_info >= (3, 14): new_function.__annotate__ = f.__annotate__ else: new_function.__annotations__ = f.__annotations__ - new_function.__doc__ = f.__doc__ - new_function.__defaults__ = f.__defaults__ - new_function.__kwdefaults__ = f.__kwdefaults__ + return new_function diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/src/typeguard/_transformer.py new/typeguard-4.4.4/src/typeguard/_transformer.py --- old/typeguard-4.4.2/src/typeguard/_transformer.py 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/src/typeguard/_transformer.py 2025-06-18 11:54:49.000000000 +0200 @@ -373,7 +373,7 @@ if isinstance(node.op, BitOr): # If either branch of the BinOp has been transformed to `None`, it means - # that a type in the union was ignored, so the entire annotation should e + # that a type in the union was ignored, so the entire annotation should be # ignored if not hasattr(node, "left") or not hasattr(node, "right"): return None @@ -384,6 +384,7 @@ elif self._memo.name_matches(node.right, *anytype_names): return node.right + # Turn union types to typing.Union constructs on Python 3.9 if sys.version_info < (3, 10): union_name = self.transformer._get_import("typing", "Union") return Subscript( diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/src/typeguard/_union_transformer.py new/typeguard-4.4.4/src/typeguard/_union_transformer.py --- old/typeguard-4.4.2/src/typeguard/_union_transformer.py 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/src/typeguard/_union_transformer.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,43 +0,0 @@ -""" -Transforms lazily evaluated PEP 604 unions into typing.Unions, for compatibility with -Python versions older than 3.10. -""" - -from __future__ import annotations - -from ast import ( - BinOp, - BitOr, - Load, - Name, - NodeTransformer, - Subscript, - Tuple, - fix_missing_locations, - parse, -) -from types import CodeType -from typing import Any - - -class UnionTransformer(NodeTransformer): - def __init__(self, union_name: Name | None = None): - self.union_name = union_name or Name(id="Union", ctx=Load()) - - def visit_BinOp(self, node: BinOp) -> Any: - self.generic_visit(node) - if isinstance(node.op, BitOr): - return Subscript( - value=self.union_name, - slice=Tuple(elts=[node.left, node.right], ctx=Load()), - ctx=Load(), - ) - - return node - - -def compile_type_hint(hint: str) -> CodeType: - parsed = parse(hint, "<string>", "eval") - UnionTransformer().visit(parsed) - fix_missing_locations(parsed) - return compile(parsed, "<string>", "eval", flags=0) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/src/typeguard/_utils.py new/typeguard-4.4.4/src/typeguard/_utils.py --- old/typeguard-4.4.2/src/typeguard/_utils.py 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/src/typeguard/_utils.py 2025-06-18 11:54:49.000000000 +0200 @@ -4,52 +4,41 @@ import sys from importlib import import_module from inspect import currentframe -from types import CodeType, FrameType, FunctionType -from typing import TYPE_CHECKING, Any, Callable, ForwardRef, Union, cast, final -from weakref import WeakValueDictionary +from types import FrameType +from typing import ( + TYPE_CHECKING, + Any, + Callable, + ForwardRef, + Union, + cast, + final, + get_args, + get_origin, +) if TYPE_CHECKING: from ._memo import TypeCheckMemo if sys.version_info >= (3, 14): - from typing import get_args, get_origin def evaluate_forwardref(forwardref: ForwardRef, memo: TypeCheckMemo) -> Any: return forwardref.evaluate( globals=memo.globals, locals=memo.locals, type_params=() ) - elif sys.version_info >= (3, 13): - from typing import get_args, get_origin def evaluate_forwardref(forwardref: ForwardRef, memo: TypeCheckMemo) -> Any: return forwardref._evaluate( memo.globals, memo.locals, type_params=(), recursive_guard=frozenset() ) - -elif sys.version_info >= (3, 10): - from typing import get_args, get_origin - - def evaluate_forwardref(forwardref: ForwardRef, memo: TypeCheckMemo) -> Any: - return forwardref._evaluate( - memo.globals, memo.locals, recursive_guard=frozenset() - ) - else: - from typing_extensions import get_args, get_origin - - evaluate_extra_args: tuple[frozenset[Any], ...] = ( - (frozenset(),) if sys.version_info >= (3, 9) else () - ) def evaluate_forwardref(forwardref: ForwardRef, memo: TypeCheckMemo) -> Any: - from ._union_transformer import compile_type_hint - - if not forwardref.__forward_evaluated__: - forwardref.__forward_code__ = compile_type_hint(forwardref.__forward_arg__) - try: - return forwardref._evaluate(memo.globals, memo.locals, *evaluate_extra_args) + return forwardref._evaluate( + memo.globals, memo.locals, recursive_guard=frozenset() + ) except NameError: if sys.version_info < (3, 10): # Try again, with the type substitutions (list -> List etc.) in place @@ -57,15 +46,12 @@ new_globals.setdefault("Union", Union) return forwardref._evaluate( - new_globals, memo.locals or new_globals, *evaluate_extra_args + new_globals, memo.locals or new_globals, recursive_guard=frozenset() ) raise -_functions_map: WeakValueDictionary[CodeType, FunctionType] = WeakValueDictionary() - - def get_type_name(type_: Any) -> str: name: str for attrname in "__name__", "_name", "__forward_arg__": diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/tests/pep695.py new/typeguard-4.4.4/tests/pep695.py --- old/typeguard-4.4.2/tests/pep695.py 1970-01-01 01:00:00.000000000 +0100 +++ new/typeguard-4.4.4/tests/pep695.py 2025-06-18 11:54:49.000000000 +0200 @@ -0,0 +1,12 @@ +from typeguard import typechecked + + +@typechecked +class ParametrizedClass[T]: + def method(self, x: T, y: str) -> T: + return x + + +@typechecked +def parametrized_func[T](x: T, y: str) -> T: + return x diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/tests/test_checkers.py new/typeguard-4.4.4/tests/test_checkers.py --- old/typeguard-4.4.2/tests/test_checkers.py 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/tests/test_checkers.py 2025-06-18 11:54:49.000000000 +0200 @@ -897,8 +897,13 @@ @pytest.mark.skipif(sys.version_info < (3, 10), reason="UnionType requires 3.10") def test_raw_uniontype_fail(self): + if sys.version_info < (3, 14): + expected_type = r"\w+\.UnionType" + else: + expected_type = "Union" + with pytest.raises( - TypeCheckError, match=r"class str is not an instance of \w+\.UnionType$" + TypeCheckError, match=f"class str is not an instance of {expected_type}$" ): check_type(str, types.UnionType) @@ -969,6 +974,9 @@ "class int is not a subclass of str" ) + def test_parametrized_value(self): + check_type(list[str], type[list[str]]) + @pytest.mark.parametrize( "value", [pytest.param(str, id="str"), pytest.param(int, id="int")] ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/tests/test_instrumentation.py new/typeguard-4.4.4/tests/test_instrumentation.py --- old/typeguard-4.4.2/tests/test_instrumentation.py 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/tests/test_instrumentation.py 2025-06-18 11:54:49.000000000 +0200 @@ -78,9 +78,18 @@ def deferredannos(method: str): if sys.version_info < (3, 14): raise pytest.skip("Deferred annotations are only supported in Python 3.14+") + return _fixture_module("deferredannos", method) +@pytest.fixture(scope="module") +def pep695(method: str): + if sys.version_info < (3, 12): + raise pytest.skip("PEP 695 type parameter syntax requires Python 3.12+") + + return _fixture_module("pep695", method) + + def test_type_checked_func(dummymodule): assert dummymodule.type_checked_func(2, 3) == 6 @@ -386,3 +395,25 @@ match=r'argument "x" \(int\) is not an instance of deferredannos.NotYetDefined', ): deferredannos.uses_forwardref(1) + + +class TestParametrized: + def test_success_func(self, pep695): + assert pep695.parametrized_func(1, "2") == 1 + + def test_success_method(self, pep695): + assert pep695.ParametrizedClass[int]().method(1, "2") == 1 + + def test_failure_func(self, pep695): + with pytest.raises( + TypeCheckError, + match=r'argument "y" \(int\) is not an instance of str', + ): + pep695.parametrized_func(1, 2) + + def test_failure_method(self, pep695): + with pytest.raises( + TypeCheckError, + match=r'argument "y" \(int\) is not an instance of str', + ): + pep695.ParametrizedClass[int]().method("str", 2) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/tests/test_typechecked.py new/typeguard-4.4.4/tests/test_typechecked.py --- old/typeguard-4.4.2/tests/test_typechecked.py 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/tests/test_typechecked.py 2025-06-18 11:54:49.000000000 +0200 @@ -692,3 +692,18 @@ assert Foo().x(1) == "second" with pytest.raises(TypeCheckError): Foo().x("wrong") + + +def test_duplicate_function(): + @typechecked + def foo() -> list[int]: # noqa: F811 + return [x for x in range(5)] + + foo1 = foo + + @typechecked + def foo() -> list[int]: # noqa: F811 + return [x for x in range(5, 10)] + + assert foo1() == [0, 1, 2, 3, 4] + assert foo() == [5, 6, 7, 8, 9] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typeguard-4.4.2/tests/test_union_transformer.py new/typeguard-4.4.4/tests/test_union_transformer.py --- old/typeguard-4.4.2/tests/test_union_transformer.py 2025-02-16 17:27:08.000000000 +0100 +++ new/typeguard-4.4.4/tests/test_union_transformer.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,44 +0,0 @@ -import typing -from typing import Callable, Union - -import pytest -from typing_extensions import Literal - -from typeguard._union_transformer import compile_type_hint - -eval_globals = { - "Callable": Callable, - "Literal": Literal, - "typing": typing, - "Union": Union, -} - - -@pytest.mark.parametrize( - "inputval, expected", - [ - ["str | int", "Union[str, int]"], - ["str | int | bytes", "Union[str, int, bytes]"], - ["str | Union[int | bytes, set]", "Union[str, int, bytes, set]"], - ["str | int | Callable[..., bytes]", "Union[str, int, Callable[..., bytes]]"], - ["str | int | Callable[[], bytes]", "Union[str, int, Callable[[], bytes]]"], - [ - "str | int | Callable[[], bytes | set]", - "Union[str, int, Callable[[], Union[bytes, set]]]", - ], - ["str | int | Literal['foo']", "Union[str, int, Literal['foo']]"], - ["str | int | Literal[-1]", "Union[str, int, Literal[-1]]"], - ["str | int | Literal[-1]", "Union[str, int, Literal[-1]]"], - [ - 'str | int | Literal["It\'s a string \'\\""]', - "Union[str, int, Literal['It\\'s a string \\'\"']]", - ], - ], -) -def test_union_transformer(inputval: str, expected: str) -> None: - code = compile_type_hint(inputval) - evaluated = eval(code, eval_globals) - evaluated_repr = repr(evaluated) - evaluated_repr = evaluated_repr.replace("typing.", "") - evaluated_repr = evaluated_repr.replace("typing_extensions.", "") - assert evaluated_repr == expected