Skip to content

Commit 3eabe68

Browse files
committed
Improve #192 by using inspect module methods
1 parent 47063fa commit 3eabe68

File tree

14 files changed

+127
-5
lines changed

14 files changed

+127
-5
lines changed

slack_bolt/kwargs_injection/async_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# pytype: skip-file
2+
import inspect
23
import logging
34
from typing import Callable, Dict, Optional, Any, Sequence
45

@@ -25,6 +26,7 @@ def build_async_required_kwargs(
2526
request: AsyncBoltRequest,
2627
response: Optional[BoltResponse],
2728
next_func: Callable[[], None] = None,
29+
this_func: Optional[Callable] = None,
2830
) -> Dict[str, Any]:
2931
all_available_args = {
3032
"logger": logger,
@@ -73,8 +75,12 @@ def build_async_required_kwargs(
7375
if first_arg_name in {"self", "cls"}:
7476
required_arg_names.pop(0)
7577
elif first_arg_name not in all_available_args.keys():
76-
logger.warning(warning_skip_uncommon_arg_name(first_arg_name))
77-
required_arg_names.pop(0)
78+
if this_func is None:
79+
logger.warning(warning_skip_uncommon_arg_name(first_arg_name))
80+
required_arg_names.pop(0)
81+
elif inspect.ismethod(this_func):
82+
# We are sure that we should skip manipulating this arg
83+
required_arg_names.pop(0)
7884

7985
kwargs: Dict[str, Any] = {
8086
k: v for k, v in all_available_args.items() if k in required_arg_names

slack_bolt/kwargs_injection/utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# pytype: skip-file
2+
import inspect
23
import logging
34
from typing import Callable, Dict, Optional, Any, Sequence
45

@@ -25,6 +26,7 @@ def build_required_kwargs(
2526
request: BoltRequest,
2627
response: Optional[BoltResponse],
2728
next_func: Callable[[], None] = None,
29+
this_func: Optional[Callable] = None,
2830
) -> Dict[str, Any]:
2931
all_available_args = {
3032
"logger": logger,
@@ -73,8 +75,12 @@ def build_required_kwargs(
7375
if first_arg_name in {"self", "cls"}:
7476
required_arg_names.pop(0)
7577
elif first_arg_name not in all_available_args.keys():
76-
logger.warning(warning_skip_uncommon_arg_name(first_arg_name))
77-
required_arg_names.pop(0)
78+
if this_func is None:
79+
logger.warning(warning_skip_uncommon_arg_name(first_arg_name))
80+
required_arg_names.pop(0)
81+
elif inspect.ismethod(this_func):
82+
# We are sure that we should skip manipulating this arg
83+
required_arg_names.pop(0)
7884

7985
kwargs: Dict[str, Any] = {
8086
k: v for k, v in all_available_args.items() if k in required_arg_names

slack_bolt/lazy_listener/async_internals.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ async def request_wired_wrapper() -> None:
2323
required_arg_names=arg_names,
2424
request=request,
2525
response=None,
26+
this_func=internal_func,
2627
)
2728
)
2829
except Exception as e:

slack_bolt/lazy_listener/internals.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def request_wired_func_wrapper() -> None:
2323
required_arg_names=arg_names,
2424
request=request,
2525
response=None,
26+
this_func=func,
2627
)
2728
)
2829
except Exception as e:

slack_bolt/listener/async_listener.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ async def run_ack_function(
117117
required_arg_names=self.arg_names,
118118
request=request,
119119
response=response,
120+
this_func=self.ack_function,
120121
)
121122
)
122123

slack_bolt/listener/custom_listener.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ def run_ack_function(
5252
required_arg_names=self.arg_names,
5353
request=request,
5454
response=response,
55+
this_func=self.ack_function,
5556
)
5657
)

slack_bolt/listener_matcher/async_builtins.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ async def async_matches(self, req: AsyncBoltRequest, resp: BoltResponse) -> bool
1414
required_arg_names=self.arg_names,
1515
request=req,
1616
response=resp,
17+
this_func=self.func,
1718
)
1819
)

slack_bolt/listener_matcher/async_listener_matcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ async def async_matches(self, req: AsyncBoltRequest, resp: BoltResponse) -> bool
4545
required_arg_names=self.arg_names,
4646
request=req,
4747
response=resp,
48+
this_func=self.func,
4849
)
4950
)
5051

slack_bolt/listener_matcher/builtins.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def matches(self, req: BoltRequest, resp: BoltResponse) -> bool:
5050
required_arg_names=self.arg_names,
5151
request=req,
5252
response=resp,
53+
this_func=self.func,
5354
)
5455
)
5556

slack_bolt/listener_matcher/custom_listener_matcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ def matches(self, req: BoltRequest, resp: BoltResponse) -> bool:
2828
required_arg_names=self.arg_names,
2929
request=req,
3030
response=resp,
31+
this_func=self.func,
3132
)
3233
)

0 commit comments

Comments
 (0)