commit: 36f8b5dee93810b8f17a7ddaf4005a5c96e52229 Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Wed May 14 08:33:06 2025 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Wed May 14 11:59:26 2025 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=36f8b5de
dev-python/typing-inspection: Enable py3.14 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> .../files/typing-inspection-0.4.0-py314.patch | 155 +++++++++++++++++++++ .../typing-inspection-0.4.0-r1.ebuild | 30 ++++ 2 files changed, 185 insertions(+) diff --git a/dev-python/typing-inspection/files/typing-inspection-0.4.0-py314.patch b/dev-python/typing-inspection/files/typing-inspection-0.4.0-py314.patch new file mode 100644 index 000000000000..fd6b76be9162 --- /dev/null +++ b/dev-python/typing-inspection/files/typing-inspection-0.4.0-py314.patch @@ -0,0 +1,155 @@ +From aec589d8abf26aa010c971666386b7edeb760852 Mon Sep 17 00:00:00 2001 +From: Viicos <[email protected]> +Date: Sat, 22 Mar 2025 13:33:54 +0100 +Subject: [PATCH] Fix compatibility with latest Python 3.14 release + +Adapt documentation and tests related to the `typing.Union` +changes +--- + docs/usage.md | 8 +-- + src/typing_inspection/introspection.py | 70 ++++++++++++++++++++++ + tests/typing_objects/test_member_checks.py | 8 ++- + 3 files changed, 81 insertions(+), 5 deletions(-) + +diff --git a/docs/usage.md b/docs/usage.md +index c9ece27..7a538c6 100644 +--- a/docs/usage.md ++++ b/docs/usage.md +@@ -4,18 +4,18 @@ The library is divided into two submodules: + + - [`typing_inspection.typing_objects`][]: provides functions to check if a variable is a [`typing`][] object: + ```python +- from typing_extensions import Union, get_origin ++ from typing_extensions import Literal, get_origin + +- from typing_inspection.typing_objects import is_union ++ from typing_inspection.typing_objects import is_literal + +- is_union(get_origin(Union[int, str])) # True ++ is_literal(get_origin(Literal[1, 2])) # True + ``` + + !!! note + You might be tempted to use a simple identity check: + + ```pycon +- >>> get_origin(Union[int, str]) is typing.Union ++ >>> get_origin(Literal[1, 2]) is typing.Literal + ``` + + However, [`typing_extensions`][] might provide a different version of the [`typing`][] objects. Instead, +diff --git a/src/typing_inspection/introspection.py b/src/typing_inspection/introspection.py +index 43cce1e..4f92527 100644 +--- a/src/typing_inspection/introspection.py ++++ b/src/typing_inspection/introspection.py +@@ -23,6 +23,40 @@ + 'is_union_origin', + ) + ++if sys.version_info >= (3, 14): ++ ++ def is_union_origin(obj: Any, /) -> bool: ++ """Return whether the provided origin is the union form. ++ ++ ```pycon ++ >>> is_union_origin(typing.Union) ++ True ++ >>> is_union_origin(get_origin(int | str)) ++ True ++ >>> is_union_origin(types.UnionType) ++ True ++ ``` ++ ++ !!! note ++ Starting in Python 3.14, the [`typing.Union`][] special form [was changed](https://github.com/python/cpython/pull/105511) ++ to be an alias to [`types.UnionType`][]. As such, it is recommended to not use this function ++ anymore (provided that you only support Python 3.14 or greater), and instead perform ++ the check directly: ++ ++ ```python ++ import types ++ from typing import Union, get_origin ++ ++ typ = Union[int, str] ++ origin = get_origin(typ) ++ if origin is types.UnionType: ++ ... ++ ``` ++ """ ++ return obj is types.UnionType ++ return typing_objects.is_union(obj) or obj is types.UnionType ++ ++ + if sys.version_info >= (3, 10): + + def is_union_origin(obj: Any, /) -> bool: +@@ -33,7 +67,25 @@ def is_union_origin(obj: Any, /) -> bool: + True + >>> is_union_origin(get_origin(int | str)) + True ++ >>> is_union_origin(types.UnionType) ++ True + ``` ++ ++ !!! note ++ Starting in Python 3.14, the [`typing.Union`][] special form [was changed](https://github.com/python/cpython/pull/105511) ++ to be an alias to [`types.UnionType`][]. As such, it is recommended to not use this function ++ anymore (provided that you only support Python 3.14 or greater), and instead perform ++ the check directly: ++ ++ ```python ++ import types ++ from typing import Union, get_origin ++ ++ typ = Union[int, str] ++ origin = get_origin(typ) ++ if origin is types.UnionType: ++ ... ++ ``` + """ + return typing_objects.is_union(obj) or obj is types.UnionType + +@@ -47,7 +99,25 @@ def is_union_origin(obj: Any, /) -> bool: + True + >>> is_union_origin(get_origin(int | str)) + True ++ >>> is_union_origin(types.UnionType) ++ True + ``` ++ ++ !!! note ++ Starting in Python 3.14, the [`typing.Union`][] special form [was changed](https://github.com/python/cpython/pull/105511) ++ to be an alias to [`types.UnionType`][]. As such, it is recommended to not use this function ++ anymore (provided that you only support Python 3.14 or greater), and instead perform ++ the check directly: ++ ++ ```python ++ import types ++ from typing import Union, get_origin ++ ++ typ = Union[int, str] ++ origin = get_origin(typ) ++ if origin is types.UnionType: ++ ... ++ ``` + """ + return typing_objects.is_union(obj) + +diff --git a/tests/typing_objects/test_member_checks.py b/tests/typing_objects/test_member_checks.py +index 86d9761..2cc5df0 100644 +--- a/tests/typing_objects/test_member_checks.py ++++ b/tests/typing_objects/test_member_checks.py +@@ -189,6 +189,12 @@ def test_is_deprecated(deprecated: deprecated) -> None: + # Misc. tests: + + [email protected](sys.version_info < (3, 10), reason='`types.UnionType` is only available in Python 3.10.') [email protected]( ++ sys.version_info < (3, 10) or sys.version_info >= (3, 14), ++ reason=( ++ '`types.UnionType` is only available in Python 3.10. ' ++ 'In Python 3.14, `typing.Union` is an alias for `types.UnionType`.' ++ ), ++) + def test_is_union_does_not_match_uniontype() -> None: + assert not typing_objects.is_union(types.UnionType) diff --git a/dev-python/typing-inspection/typing-inspection-0.4.0-r1.ebuild b/dev-python/typing-inspection/typing-inspection-0.4.0-r1.ebuild new file mode 100644 index 000000000000..102acc25ab04 --- /dev/null +++ b/dev-python/typing-inspection/typing-inspection-0.4.0-r1.ebuild @@ -0,0 +1,30 @@ +# Copyright 2025 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +DISTUTILS_USE_PEP517=hatchling +PYTHON_COMPAT=( pypy3_11 python3_{11..14} ) + +inherit distutils-r1 pypi + +DESCRIPTION="Runtime typing introspection tools" +HOMEPAGE=" + https://github.com/pydantic/typing-inspection/ + https://pypi.org/project/typing-inspection/ +" + +LICENSE="MIT" +SLOT="0" +KEYWORDS="~amd64 ~arm ~arm64 ~loong ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86" + +RDEPEND=" + >=dev-python/typing-extensions-4.12.0[${PYTHON_USEDEP}] +" + +distutils_enable_tests pytest + +PATCHES=( + # https://github.com/pydantic/typing-inspection/pull/37 + "${FILESDIR}/${P}-py314.patch" +)
