From 993fcc565801c03595f36cfd8a99ba0d8fa63f76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Wed, 13 Jul 2022 10:21:08 +0200 Subject: [PATCH] Backport a fix for Python 3.11.0b4 --- 2484942b4f.patch | 70 ++++++++++++++++++++++++++++++++++++++++++ python-hypothesis.spec | 1 + 2 files changed, 71 insertions(+) create mode 100644 2484942b4f.patch diff --git a/2484942b4f.patch b/2484942b4f.patch new file mode 100644 index 0000000..e52af0c --- /dev/null +++ b/2484942b4f.patch @@ -0,0 +1,70 @@ +From 2484942b4f9ff63e6c3c0dae2097a266622fc87d Mon Sep 17 00:00:00 2001 +From: Zac Hatfield-Dodds +Date: Wed, 22 Jun 2022 22:41:38 -0700 +Subject: [PATCH] Support 3.11 GenericAlias again + +--- + hypothesis-python/RELEASE.rst | 4 ++++ + .../src/hypothesis/strategies/_internal/types.py | 13 +++++-------- + 2 files changed, 9 insertions(+), 8 deletions(-) + create mode 100644 hypothesis-python/RELEASE.rst + +diff --git a/hypothesis-python/RELEASE.rst b/hypothesis-python/RELEASE.rst +new file mode 100644 +index 0000000000..6b49da62d3 +--- /dev/null ++++ b/hypothesis-python/RELEASE.rst +@@ -0,0 +1,4 @@ ++RELEASE_TYPE: patch ++ ++This patch fixes :func:`~hypothesis.strategies.from_type` on Python 3.11, ++following `python/cpython#93754 `__. +diff --git a/hypothesis-python/src/hypothesis/strategies/_internal/types.py b/hypothesis-python/src/hypothesis/strategies/_internal/types.py +index 617b360856..4e410bcf58 100644 +--- a/hypothesis-python/src/hypothesis/strategies/_internal/types.py ++++ b/hypothesis-python/src/hypothesis/strategies/_internal/types.py +@@ -39,11 +39,13 @@ + from hypothesis.strategies._internal.lazy import unwrap_strategies + from hypothesis.strategies._internal.strategies import OneOfStrategy + ++GenericAlias: typing.Any + UnionType: typing.Any + try: + # The type of PEP-604 unions (`int | str`), added in Python 3.10 +- from types import UnionType ++ from types import GenericAlias, UnionType + except ImportError: ++ GenericAlias = () + UnionType = () + + try: +@@ -51,11 +53,6 @@ + except ImportError: + typing_extensions = None # type: ignore + +-try: +- from typing import _GenericAlias # type: ignore # python >= 3.7 +-except ImportError: +- _GenericAlias = () +- + try: + from typing import _AnnotatedAlias # type: ignore + except ImportError: +@@ -298,7 +295,7 @@ def find_annotated_strategy(annotated_type): # pragma: no cover + def has_type_arguments(type_): + """Decides whethere or not this type has applied type arguments.""" + args = getattr(type_, "__args__", None) +- if args and isinstance(type_, _GenericAlias): ++ if args and isinstance(type_, (typing._GenericAlias, GenericAlias)): + # There are some cases when declared types do already have type arguments + # Like `Sequence`, that is `_GenericAlias(abc.Sequence[T])[T]` + parameters = getattr(type_, "__parameters__", None) +@@ -312,7 +309,7 @@ def is_generic_type(type_): + # The ugly truth is that `MyClass`, `MyClass[T]`, and `MyClass[int]` are very different. + # We check for `MyClass[T]` and `MyClass[int]` with the first condition, + # while the second condition is for `MyClass`. +- return isinstance(type_, typing_root_type) or ( ++ return isinstance(type_, typing_root_type + (GenericAlias,)) or ( + isinstance(type_, type) and typing.Generic in type_.__mro__ + ) + diff --git a/python-hypothesis.spec b/python-hypothesis.spec index 2789e3a..3009a6e 100644 --- a/python-hypothesis.spec +++ b/python-hypothesis.spec @@ -20,6 +20,7 @@ Source0: %{url}/archive/hypothesis-python-%{version}/hypothesis-%{version # Python 3.11 fixes Patch: https://github.com/HypothesisWorks/hypothesis/commit/6d1d17d016.patch Patch: https://github.com/HypothesisWorks/hypothesis/commit/a4681f6962.patch +Patch: https://github.com/HypothesisWorks/hypothesis/commit/2484942b4f.patch BuildArch: noarch