Skip to content

Commit b71a797

Browse files
authored
refactor: 🎨 Better organization of the entrypoint.py file
1 parent db8317a commit b71a797

2 files changed

Lines changed: 40 additions & 40 deletions

File tree

injection/entrypoint.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from contextlib import asynccontextmanager, contextmanager
66
from dataclasses import dataclass, field
77
from functools import wraps
8-
from types import MethodType
98
from types import ModuleType as PythonModule
109
from typing import TYPE_CHECKING, Any, Concatenate, Protocol, Self, final, overload
1110

@@ -15,7 +14,14 @@
1514
__all__ = ("AsyncEntrypoint", "Entrypoint", "entrypointmaker")
1615

1716

18-
class _EntrypointDecorator[**P, T1, T2](Protocol):
17+
type AsyncEntrypoint[**P, T] = Entrypoint[P, Coroutine[Any, Any, T]]
18+
type EntrypointSetupMethod[**P, **EPP, T1, T2] = Callable[
19+
Concatenate[Entrypoint[EPP, T1], P],
20+
Entrypoint[EPP, T2],
21+
]
22+
23+
24+
class EntrypointDecorator[**P, T1, T2](Protocol):
1925
if TYPE_CHECKING: # pragma: no cover
2026

2127
@overload
@@ -45,12 +51,6 @@ def __call__(
4551
) -> Any: ...
4652

4753

48-
type AsyncEntrypoint[**P, T] = Entrypoint[P, Coroutine[Any, Any, T]]
49-
type EntrypointSetupMethod[**P, **EPP, T1, T2] = Callable[
50-
Concatenate[Entrypoint[EPP, T1], P],
51-
Entrypoint[EPP, T2],
52-
]
53-
5454
# SMP = Setup Method Parameters
5555
# EPP = EntryPoint Parameters
5656

@@ -62,7 +62,7 @@ def entrypointmaker[**SMP, **EPP, T1, T2](
6262
/,
6363
*,
6464
profile_loader: ProfileLoader = ...,
65-
) -> _EntrypointDecorator[EPP, T1, T2]: ...
65+
) -> EntrypointDecorator[EPP, T1, T2]: ...
6666

6767
@overload
6868
def entrypointmaker[**SMP, **EPP, T1, T2](
@@ -72,7 +72,7 @@ def entrypointmaker[**SMP, **EPP, T1, T2](
7272
profile_loader: ProfileLoader = ...,
7373
) -> Callable[
7474
[EntrypointSetupMethod[SMP, EPP, T1, T2]],
75-
_EntrypointDecorator[EPP, T1, T2],
75+
EntrypointDecorator[EPP, T1, T2],
7676
]: ...
7777

7878

@@ -84,7 +84,7 @@ def entrypointmaker[**SMP, **EPP, T1, T2](
8484
) -> Any:
8585
def decorator(
8686
wp: EntrypointSetupMethod[SMP, EPP, T1, T2],
87-
) -> _EntrypointDecorator[EPP, T1, T2]:
87+
) -> EntrypointDecorator[EPP, T1, T2]:
8888
return Entrypoint._make_decorator(wp, profile_loader)
8989

9090
return decorator(wrapped) if wrapped else decorator
@@ -173,26 +173,26 @@ def _make_decorator[**_P, _T](
173173
setup_method: EntrypointSetupMethod[_P, P, T, _T],
174174
/,
175175
profile_loader: ProfileLoader | None = None,
176-
) -> _EntrypointDecorator[P, T, _T]:
176+
) -> EntrypointDecorator[P, T, _T]:
177177
profile_loader = profile_loader or ProfileLoader()
178178
setup_method = profile_loader.module.make_injected_function(setup_method)
179179

180180
def entrypoint_decorator(
181-
function: Callable[P, T] | None = None,
181+
wrapped: Callable[P, T] | None = None,
182182
/,
183183
*,
184184
autocall: bool = False,
185185
) -> Any:
186-
def decorator(fn: Callable[P, T]) -> Callable[P, _T]:
186+
def decorator(wp: Callable[P, T]) -> Callable[P, _T]:
187187
profile_loader.init()
188-
self = cls(fn, profile_loader)
189-
wrapper = MethodType(setup_method, self)().function
188+
self = cls(wp, profile_loader)
189+
wrapper = setup_method(self).function # type: ignore[call-arg]
190190

191191
if autocall:
192-
wrapper()
192+
wrapper() # type: ignore[call-arg]
193193

194194
return wrapper
195195

196-
return decorator(function) if function else decorator
196+
return decorator(wrapped) if wrapped else decorator
197197

198198
return entrypoint_decorator

uv.lock

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)