fastmcp 2.6.1__py3-none-any.whl → 2.7.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,101 +0,0 @@
1
- import inspect
2
- from collections.abc import Callable
3
- from typing import Generic, ParamSpec, TypeVar, cast, overload
4
-
5
- from typing_extensions import Self
6
-
7
- R = TypeVar("R")
8
- P = ParamSpec("P")
9
-
10
-
11
- class DecoratedFunction(Generic[P, R]):
12
- """Descriptor for decorated functions.
13
-
14
- You can return this object from a decorator to ensure that it works across
15
- all types of functions: vanilla, instance methods, class methods, and static
16
- methods; both synchronous and asynchronous.
17
-
18
- This class is used to store the original function and metadata about how to
19
- register it as a tool.
20
-
21
- Example usage:
22
-
23
- ```python
24
- def my_decorator(fn: Callable[P, R]) -> DecoratedFunction[P, R]:
25
- return DecoratedFunction(fn)
26
- ```
27
-
28
- On a function:
29
- ```python
30
- @my_decorator
31
- def my_function(a: int, b: int) -> int:
32
- return a + b
33
- ```
34
-
35
- On an instance method:
36
- ```python
37
- class Test:
38
- @my_decorator
39
- def my_function(self, a: int, b: int) -> int:
40
- return a + b
41
- ```
42
-
43
- On a class method:
44
- ```python
45
- class Test:
46
- @classmethod
47
- @my_decorator
48
- def my_function(cls, a: int, b: int) -> int:
49
- return a + b
50
- ```
51
-
52
- Note that for classmethods, the decorator must be applied first, then
53
- `@classmethod` on top.
54
-
55
- On a static method:
56
- ```python
57
- class Test:
58
- @staticmethod
59
- @my_decorator
60
- def my_function(a: int, b: int) -> int:
61
- return a + b
62
- ```
63
- """
64
-
65
- def __init__(self, fn: Callable[P, R]):
66
- self.fn = fn
67
-
68
- def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:
69
- """Call the original function."""
70
- try:
71
- return self.fn(*args, **kwargs)
72
- except TypeError as e:
73
- if "'classmethod' object is not callable" in str(e):
74
- raise TypeError(
75
- "To apply this decorator to a classmethod, apply the decorator first, then @classmethod on top."
76
- )
77
- raise
78
-
79
- @overload
80
- def __get__(self, instance: None, owner: type | None = None) -> Self: ...
81
-
82
- @overload
83
- def __get__(
84
- self, instance: object, owner: type | None = None
85
- ) -> Callable[P, R]: ...
86
-
87
- def __get__(
88
- self, instance: object | None, owner: type | None = None
89
- ) -> Self | Callable[P, R]:
90
- """Return the original function when accessed from an instance, or self when accessed from the class."""
91
- if instance is None:
92
- return self
93
- # Return the original function bound to the instance
94
- return cast(Callable[P, R], self.fn.__get__(instance, owner))
95
-
96
- def __repr__(self) -> str:
97
- """Return a representation that matches Python's function representation."""
98
- module = getattr(self.fn, "__module__", "unknown")
99
- qualname = getattr(self.fn, "__qualname__", str(self.fn))
100
- sig_str = str(inspect.signature(self.fn))
101
- return f"<function {module}.{qualname}{sig_str}>"