From 5a8d55e9eaee3f8ddfe8df844eb055b3b20cfce2 Mon Sep 17 00:00:00 2001
From: Cserna Zsolt <cserna.zsolt@gmail.com>
Date: Wed, 3 Apr 2024 14:55:13 +0200
Subject: [PATCH] doc: add doc.patch to fix typing.TYPE_CHECKING blocks for
 sphinx

---
 doc/conf.py           |  1 +
 doc/patch.py          | 16 ++++++++++++++++
 pyproject.toml        |  2 +-
 tests/test_release.py |  1 +
 4 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 doc/patch.py

diff --git a/doc/conf.py b/doc/conf.py
index 5eb14bc..ece0681 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -24,6 +24,7 @@
 
 sys.path.insert(0, os.path.abspath(".."))
 
+import doc.patch
 
 # -- General configuration ------------------------------------------------
 
diff --git a/doc/patch.py b/doc/patch.py
new file mode 100644
index 0000000..ff7571b
--- /dev/null
+++ b/doc/patch.py
@@ -0,0 +1,16 @@
+# this is required to make sphinx able to find references for classes put inside
+# typing.TYPE_CHECKING block
+
+from ssl import SSLContext
+
+from werkzeug.wrappers import Request
+from werkzeug.wrappers import Response
+
+import pytest_httpserver.blocking_httpserver
+import pytest_httpserver.httpserver
+
+pytest_httpserver.httpserver.SSLContext = SSLContext
+pytest_httpserver.blocking_httpserver.SSLContext = SSLContext
+
+pytest_httpserver.blocking_httpserver.Request = Request
+pytest_httpserver.blocking_httpserver.Response = Response
diff --git a/pyproject.toml b/pyproject.toml
index 26e771d..efab25d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -87,7 +87,7 @@ markers = [
 ]
 
 [tool.mypy]
-files = ["pytest_httpserver", "scripts", "tests", "doc"]
+files = ["pytest_httpserver", "scripts", "tests"]
 implicit_reexport = false
 
 
diff --git a/tests/test_release.py b/tests/test_release.py
index 02e7f64..0067147 100644
--- a/tests/test_release.py
+++ b/tests/test_release.py
@@ -183,6 +183,7 @@ def test_sdist_contents(build: Build, version: str):
             "howto.rst",
             "index.rst",
             "Makefile",
+            "patch.py",
             "tutorial.rst",
             "upgrade.rst",
         },