Blob Blame History Raw
From 6d1d17d016d092146b620e4f9338f9b125e33ded Mon Sep 17 00:00:00 2001
From: Florian Bruhin <me@the-compiler.org>
Date: Tue, 26 Apr 2022 11:16:27 +0200
Subject: [PATCH] Adjust imports of deprecated sre_* modules in Python 3.11

Fixes #3309
See https://github.com/python/cpython/issues/91308

I don't see a way to avoid relying on Python 3.11 internals here, so
this instead just adjusts the imports to avoid deprecation warnings.
---
 .../src/hypothesis/strategies/_internal/regex.py         | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/hypothesis-python/src/hypothesis/strategies/_internal/regex.py b/hypothesis-python/src/hypothesis/strategies/_internal/regex.py
index 5da2b3ba2d..b93e8d192b 100644
--- a/hypothesis-python/src/hypothesis/strategies/_internal/regex.py
+++ b/hypothesis-python/src/hypothesis/strategies/_internal/regex.py
@@ -10,8 +10,13 @@
 
 import operator
 import re
-import sre_constants as sre
-import sre_parse
+
+try:  # pragma: no cover
+    import re._constants as sre
+    import re._parser as sre_parse
+except ImportError:  # Python < 3.11
+    import sre_constants as sre  # type: ignore
+    import sre_parse  # type: ignore
 
 from hypothesis import reject, strategies as st
 from hypothesis.internal.charmap import as_general_categories, categories