-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #709 Enable developers to inject non-bolt arguments to listener function args #712
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import warnings | ||
from logging import Logger | ||
from typing import Optional, Callable, Dict, Any | ||
|
||
|
@@ -13,6 +14,7 @@ | |
from slack_bolt.context.context import BoltContext | ||
from slack_bolt.error import BoltError | ||
from slack_bolt.util.utils import get_arg_names_of_callable | ||
from slack_bolt.warning import BoltCodeWarning | ||
|
||
|
||
class Authorize: | ||
|
@@ -81,8 +83,9 @@ def __call__( | |
found_arg_names = kwargs.keys() | ||
for name in self.arg_names: | ||
if name not in found_arg_names: | ||
self.logger.warning(f"{name} is not a valid argument") | ||
kwargs[name] = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To allow developers to inject extra args, we remove this logic |
||
warnings.warn( | ||
f"{name} may not be a valid argument name, which bolt-python cannot handle", BoltCodeWarning | ||
) | ||
|
||
auth_result = self.func(**kwargs) | ||
if auth_result is None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# pytype: skip-file | ||
import inspect | ||
import logging | ||
import warnings | ||
from typing import Callable, Dict, Optional, Any, Sequence | ||
|
||
from slack_bolt.request.async_request import AsyncBoltRequest | ||
|
@@ -17,6 +18,7 @@ | |
to_step, | ||
) | ||
from ..logger.messages import warning_skip_uncommon_arg_name | ||
from ..warning import BoltCodeWarning | ||
|
||
|
||
def build_async_required_kwargs( | ||
|
@@ -85,7 +87,8 @@ def build_async_required_kwargs( | |
required_arg_names.pop(0) | ||
elif first_arg_name not in all_available_args.keys(): | ||
if this_func is None: | ||
logger.warning(warning_skip_uncommon_arg_name(first_arg_name)) | ||
# Actually, it's rare to see this warning | ||
warnings.warn(warning_skip_uncommon_arg_name(first_arg_name), BoltCodeWarning) | ||
required_arg_names.pop(0) | ||
elif inspect.ismethod(this_func): | ||
# We are sure that we should skip manipulating this arg | ||
|
@@ -98,9 +101,9 @@ def build_async_required_kwargs( | |
if isinstance(request, AsyncBoltRequest): | ||
kwargs[name] = AsyncArgs(**all_available_args) | ||
else: | ||
# We don't use BolCodeWarning here because something unexpected (e.g., bolt-python bug) may be the cause | ||
logger.warning(f"Unknown Request object type detected ({type(request)})") | ||
|
||
if name not in found_arg_names: | ||
logger.warning(f"{name} is not a valid argument") | ||
kwargs[name] = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To allow developers to inject extra args, we remove this logic |
||
warnings.warn(f"{name} may not be a valid argument name, which bolt-python cannot handle", BoltCodeWarning) | ||
return kwargs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# pytype: skip-file | ||
import inspect | ||
import logging | ||
import warnings | ||
from typing import Callable, Dict, Optional, Any, Sequence | ||
|
||
from slack_bolt.request import BoltRequest | ||
|
@@ -17,6 +18,7 @@ | |
to_step, | ||
) | ||
from ..logger.messages import warning_skip_uncommon_arg_name | ||
from ..warning import BoltCodeWarning | ||
|
||
|
||
def build_required_kwargs( | ||
|
@@ -85,7 +87,8 @@ def build_required_kwargs( | |
required_arg_names.pop(0) | ||
elif first_arg_name not in all_available_args.keys(): | ||
if this_func is None: | ||
logger.warning(warning_skip_uncommon_arg_name(first_arg_name)) | ||
# Actually, it's rare to see this warning | ||
warnings.warn(warning_skip_uncommon_arg_name(first_arg_name), BoltCodeWarning) | ||
required_arg_names.pop(0) | ||
elif inspect.ismethod(this_func): | ||
# We are sure that we should skip manipulating this arg | ||
|
@@ -98,9 +101,9 @@ def build_required_kwargs( | |
if isinstance(request, BoltRequest): | ||
kwargs[name] = Args(**all_available_args) | ||
else: | ||
# We don't use BolCodeWarning here because something unexpected (e.g., bolt-python bug) may be the cause | ||
logger.warning(f"Unknown Request object type detected ({type(request)})") | ||
|
||
if name not in found_arg_names: | ||
logger.warning(f"{name} is not a valid argument") | ||
kwargs[name] = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To allow developers to inject extra args, we remove this logic |
||
warnings.warn(f"{name} may not be a valid argument name, which bolt-python cannot handle", BoltCodeWarning) | ||
return kwargs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"""Warnings by Bolt for Python | ||
|
||
Developers can ignore the following warning categories as necessary. | ||
see also: https://docs.python.org/3/library/warnings.html#default-warning-filter | ||
""" | ||
|
||
|
||
class BoltCodeWarning(UserWarning): | ||
"""Warning to help developers notice their coding errors. | ||
This warning should not be used for informing configuration errors in the App/AsyncApp constructor. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To allow developers to inject extra args, we remove this logic