Repository: hynek/svcs (language: python)

Issue:
`get_type_hints` fails on any of the `svcs` types
<!--

Please use issues ONLY for BUGS.

For questions, please use <https://github.com/hynek/svcs/discussions/categories/q-a>

For feature requests, please use <https://github.com/hynek/svcs/discussions/categories/ideas>

Thank you!

-->

A minimal reproduction:

```python
from svcs import Registry
from typing import get_type_hints

get_type_hints(Registry)
```

The reason for this is the changing of the module of the different types [here](https://github.com/hynek/svcs/blob/c5c5f48f3a102e1619524ae3c0d069fbb1a6370d/src/svcs/__init__.py#L50-L56). This fails since `get_type_hints` depends on the `__module__` of the given object to find the global namespace in order to resolve stringified annotations.


EDIT: Finished writing the description since I hit enter by accident before finishing the writing the issue descritpion.
`get_type_hints` fails on any of the `svcs` types
<!--

Please use issues ONLY for BUGS.

For questions, please use <https://github.com/hynek/svcs/discussions/categories/q-a>

For feature requests, please use <https://github.com/hynek/svcs/discussions/categories/ideas>

Thank you!

-->

A minimal reproduction:

```python
from svcs import Registry
from typing import get_type_hints

get_type_hints(Registry)
```

The reason for this is the changing of the module of the different types [here](https://github.com/hynek/svcs/blob/c5c5f48f3a102e1619524ae3c0d069fbb1a6370d/src/svcs/__init__.py#L50-L56). This fails since `get_type_hints` depends on the `__module__` of the given object to find the global namespace in order to resolve stringified annotations.


EDIT: Finished writing the description since I hit enter by accident before finishing the writing the issue descritpion.


Discussion / hints:
Does this mean we can have either nice names or a working get_type_hints? :-/
Unfortunately, I think so. Or maybe all the types used in the annotations of the different `svcs` types could be included in `svcs.__init__`. That might work (haven't tested it) but that feels.... wrong.
Does this mean we can have either nice names or a working get_type_hints? :-/
Unfortunately, I think so. Or maybe all the types used in the annotations of the different `svcs` types could be included in `svcs.__init__`. That might work (haven't tested it) but that feels.... wrong.

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6a91027..24c4b71 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,13 @@ You can find our backwards-compatibility policy [here](https://github.com/hynek/
 - Flask: `svcs.flask.registry` which is a `werkzeug.local.LocalProxy` for the currently active registry on `flask.current_app`.
 
 
+### Fixed
+
+- We've stopped rewriting the public names of our objects and `typing.get_type_hints()` now works on them as expected for Python 3.10 and later.
+  [#52](https://github.com/hynek/issues/pull/52)
+  [#53](https://github.com/hynek/issues/pull/53)
+
+
 ## [23.20.0](https://github.com/hynek/svcs/compare/23.19.0...23.20.0) - 2023-09-05
 
 ### Added
diff --git a/docs/conf.py b/docs/conf.py
index 54e58ff..eed5881 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -60,6 +60,7 @@
 exclude_patterns = ["_build"]
 
 nitpick_ignore = [
+    *[("py:class", f"svcs._core.T{i}") for i in range(1, 11)],
     # Welcome, MkDocs projects. :(
     ("py:class", "FastAPI"),
     ("py:class", "Starlette"),
diff --git a/src/svcs/__init__.py b/src/svcs/__init__.py
index 22ececd..46dc62c 100644
--- a/src/svcs/__init__.py
+++ b/src/svcs/__init__.py
@@ -45,12 +45,3 @@
     from . import starlette
 except ImportError:
     __all__ += ["starlette"]
-
-
-# Make nicer public names.
-__locals = locals()
-for __name in __all__:
-    if not __name.startswith("__") and not __name.islower():
-        __locals[__name].__module__ = "svcs"
-del __locals
-del __name  # pyright: ignore[reportUnboundVariable]


Test patch:
diff --git a/tests/test_typing.py b/tests/test_typing.py
new file mode 100644
index 0000000..5bf4e71
--- /dev/null
+++ b/tests/test_typing.py
@@ -0,0 +1,26 @@
+# SPDX-FileCopyrightText: 2023 Hynek Schlawack <hs@ox.cx>
+#
+# SPDX-License-Identifier: MIT
+
+import sys
+import typing
+
+import pytest
+
+import svcs
+
+
+@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires Python 3.10+")
+def test_get_type_hints():
+    """
+    typing.get_type_hints() works on our objects on Python 3.10+.
+
+    Unfortunately supporting older versions would require to rewrite all type
+    hints.
+
+    Regression test for #52.
+    """
+    typing.get_type_hints(svcs.Registry)
+    typing.get_type_hints(svcs.Container)
+    typing.get_type_hints(svcs.ServicePing)
+    typing.get_type_hints(svcs.RegisteredService)