diff options
author | V3n3RiX <venerix@koprulu.sector> | 2025-05-15 12:59:17 +0100 |
---|---|---|
committer | V3n3RiX <venerix@koprulu.sector> | 2025-05-15 12:59:17 +0100 |
commit | 317f7ab04be81dbdfa5b1c9c42729927c5bde946 (patch) | |
tree | b90afe9d6ef62b771a6ddb9eb1968d6338ccd206 /dev-python/typing-inspection | |
parent | 5e9cf59ef591ef814092c1f6f32d2ef2369d3882 (diff) |
Diffstat (limited to 'dev-python/typing-inspection')
3 files changed, 187 insertions, 0 deletions
diff --git a/dev-python/typing-inspection/Manifest b/dev-python/typing-inspection/Manifest index f1310dfeb957..981fba966887 100644 --- a/dev-python/typing-inspection/Manifest +++ b/dev-python/typing-inspection/Manifest @@ -1,3 +1,5 @@ +AUX typing-inspection-0.4.0-py314.patch 5662 BLAKE2B 3593bcbb4f16f2d3691cf5bf950da9e8d8ba9ed01ec31d4f90f5f2ac01df300bbcb2eb8f14a154d36a67eb8074a45332c1670cb66515eb8570a150423e2149bd SHA512 5364ba5e91c84e848e184da3c297737961a3d83926e871c37c09c2223694d73acc7d9220d770d579965f67ef8164129d07beaae4bd0f0c193bb3e20ba7864987 DIST typing_inspection-0.4.0.tar.gz 76222 BLAKE2B 08e509950b6d71d5036d91293c6773467f0d7a09ea21a54692341eb980aee6f91b364039070bc49680f4b201fa6bc8d8211d889f9fafdc2341762559354e4e0d SHA512 95e725e7db7609406f8a63dda46ac7559adf13ef5d63e44a43966977163ff69825df465fb741d288e63ee01240dc3fe8b1314b0cd5030f2d5b08d24a739b7b02 +EBUILD typing-inspection-0.4.0-r1.ebuild 667 BLAKE2B 34ff066d6eedd257d3aac0a617ca7be22e284f817cbd2bb62bdffc63da21e569654f57b49132aa1cce8ebc355b9b193f4c56b463c1097365b5393a55751014b8 SHA512 93642276840c008297a50712e9798d1375c1b6595ea590f55fe0b19a239126e7965a01c647ff7c2049d56a1e9f4315f208fca18f4e181712a0603af453aa8c62 EBUILD typing-inspection-0.4.0.ebuild 565 BLAKE2B b693409b46a896c108feb354aa1288892b3e472830b44684ba925c463e66d9eec2c4440387bc254a521950250f6d5397d1a113c28a371de2c26e9ec7600f9f32 SHA512 92acab31177db214a08365d555942514e0dacd992ba071bc4d33ed4017908377b63a671a5176b283e3582a80cf6ca9cb061d68638ba2a111504d71ca437599ce MISC metadata.xml 389 BLAKE2B 8723ee4592f9e1a686145f0e65d1157c97d3417fa506acc3bdc4cbe1feb1530cccedfd1816769affd3642d094d052840e6620822ef8d3bf8c7187968d0e22065 SHA512 df5d81c9df4560cf2f8b90184e93db335231f970cfa4ee57a3c37e782d787d6148830d874b8c08a82d820257034ff395b086264a5c4229a518a21c6f10dd7abf 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 <65306057+Viicos@users.noreply.github.com> +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: + + +-@pytest.mark.skipif(sys.version_info < (3, 10), reason='`types.UnionType` is only available in Python 3.10.') ++@pytest.mark.skipif( ++ 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" +) |