Skip to content

Commit 02a2c30

Browse files
committed
chore: clean up inspection code to remove redundant param inspection
1 parent 503c6f3 commit 02a2c30

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/mcp/server/lowlevel/func_inspection.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ def accepts_cursor(func: Callable[..., Any]) -> bool:
1919

2020
params = dict(sig.parameters.items())
2121

22-
method = inspect.ismethod(func)
23-
24-
if method:
25-
params.pop("self", None)
26-
params.pop("cls", None)
27-
2822
if len(params) == 0:
2923
# No parameters at all - can't accept cursor
3024
return False

tests/server/lowlevel/test_func_inspection.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,42 @@ async def no_cursor_method(self):
1313
"""Instance method without cursor parameter"""
1414
pass
1515

16+
# noinspection PyMethodParameters
17+
async def no_cursor_method_bad_self_name(bad): # pyright: ignore[reportSelfClsParameterName]
18+
"""Instance method with cursor parameter, but with bad self name"""
19+
pass
20+
1621
async def cursor_method(self, cursor: types.Cursor | None):
1722
"""Instance method with cursor parameter"""
1823
pass
1924

25+
# noinspection PyMethodParameters
26+
async def cursor_method_bad_self_name(bad, cursor: types.Cursor | None): # pyright: ignore[reportSelfClsParameterName]
27+
"""Instance method with cursor parameter, but with bad self name"""
28+
pass
29+
2030
@classmethod
2131
async def no_cursor_class_method(cls):
2232
"""Class method without cursor parameter"""
2333
pass
2434

35+
# noinspection PyMethodParameters
36+
@classmethod
37+
async def no_cursor_class_method_bad_cls_name(bad): # pyright: ignore[reportSelfClsParameterName]
38+
"""Class method without cursor parameter, but with bad cls name"""
39+
pass
40+
2541
@classmethod
2642
async def cursor_class_method(cls, cursor: types.Cursor | None):
2743
"""Class method with cursor parameter"""
2844
pass
2945

46+
# noinspection PyMethodParameters
47+
@classmethod
48+
async def cursor_class_method_bad_cls_name(bad, cursor: types.Cursor | None): # pyright: ignore[reportSelfClsParameterName]
49+
"""Class method with cursor parameter, but with bad cls name"""
50+
pass
51+
3052
@staticmethod
3153
async def no_cursor_static_method():
3254
"""Static method without cursor parameter"""
@@ -37,6 +59,11 @@ async def cursor_static_method(cursor: types.Cursor | None):
3759
"""Static method with cursor parameter"""
3860
pass
3961

62+
@staticmethod
63+
async def cursor_static_method_bad_arg_name(self: types.Cursor | None): # pyright: ignore[reportSelfClsParameterName]
64+
"""Static method with cursor parameter, but the cursor argument is named self"""
65+
pass
66+
4067

4168
async def no_cursor_func():
4269
"""Function without cursor parameter"""
@@ -108,13 +135,18 @@ async def mixed_positional_and_keyword(cursor: types.Cursor | None, *, extra: st
108135
(cursor_func_with_self, True, "function with param named 'self'"),
109136
# Instance methods
110137
(MyClass().no_cursor_method, False, "instance method without cursor"),
138+
(MyClass().no_cursor_method_bad_self_name, False, "instance method without cursor (bad self name)"),
111139
(MyClass().cursor_method, True, "instance method with cursor"),
140+
(MyClass().cursor_method_bad_self_name, True, "instance method with cursor (bad self name)"),
112141
# Class methods
113142
(MyClass.no_cursor_class_method, False, "class method without cursor"),
143+
(MyClass.no_cursor_class_method_bad_cls_name, False, "class method without cursor (bad cls name)"),
114144
(MyClass.cursor_class_method, True, "class method with cursor"),
145+
(MyClass.cursor_class_method_bad_cls_name, True, "class method with cursor (bad cls name)"),
115146
# Static methods
116147
(MyClass.no_cursor_static_method, False, "static method without cursor"),
117148
(MyClass.cursor_static_method, True, "static method with cursor"),
149+
(MyClass.cursor_static_method_bad_arg_name, True, "static method with cursor (bad arg name)"),
118150
# Variadic parameters
119151
(var_positional_func, True, "function with *args"),
120152
(positional_with_var_positional_func, True, "function with cursor and *args"),

0 commit comments

Comments
 (0)