Skip to content
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 #370 by adding an alias of next arg (next_) in middleware arguments #394

Merged
merged 1 commit into from
Jul 9, 2021

Conversation

seratch
Copy link
Member

@seratch seratch commented Jul 7, 2021

This pull request fixes #370. The essential change in this pull request is to add next_ to kwargs_injection names. With this fix, developers can use next_ in addition to next in the middleware method arguments.

@app.middleware
def just_call_next(next_):
    next_()

Category (place an x in each of the [ ])

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Document pages under /docs
  • Others

Requirements (place an x in each [ ])

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run ./scripts/install_all_and_run_tests.sh after making the changes.

Copy link
Member Author

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments for reviewers

@@ -87,6 +87,53 @@ def test_next_call(self):
assert response.body == "acknowledged!"
assert_auth_test_count(self, 1)

def test_decorator_next_call(self):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking these test patterns should be helpful for knowing the purpose of the changes.

@@ -45,10 +45,10 @@ def run_middleware(
for m in self.middleware:
middleware_state = {"next_called": False}

def next():
def next_():
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an essential part of this PR. It's just a minor refactoring

@@ -52,6 +52,7 @@ def build_required_kwargs(
"respond": request.context.respond,
# middleware
"next": next_func,
"next_": next_func, # for the middleware using Python's built-in `next()` function
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this enables bolt-python to resolve the alias name as well.

@codecov
Copy link

codecov bot commented Jul 7, 2021

Codecov Report

Merging #394 (4a4105d) into main (c61206d) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #394   +/-   ##
=======================================
  Coverage   91.60%   91.61%           
=======================================
  Files         167      167           
  Lines        5384     5388    +4     
=======================================
+ Hits         4932     4936    +4     
  Misses        452      452           
Impacted Files Coverage Δ
slack_bolt/kwargs_injection/async_utils.py 85.71% <ø> (ø)
slack_bolt/kwargs_injection/utils.py 85.71% <ø> (ø)
slack_bolt/logger/messages.py 90.62% <ø> (ø)
slack_bolt/middleware/async_custom_middleware.py 96.15% <ø> (ø)
slack_bolt/middleware/async_middleware.py 90.90% <ø> (ø)
...e/authorization/async_multi_teams_authorization.py 91.17% <ø> (ø)
...e/authorization/async_single_team_authorization.py 93.54% <ø> (ø)
...dleware/authorization/single_team_authorization.py 93.33% <ø> (ø)
slack_bolt/middleware/custom_middleware.py 100.00% <ø> (ø)
...listener_matches/async_message_listener_matches.py 100.00% <ø> (ø)
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c61206d...4a4105d. Read the comment docs.

Copy link
Member

@mwbrooks mwbrooks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! ✅

Just out of curiosity, is next_ a convention in Python? Rather than say nextMiddleware.

@seratch
Copy link
Member Author

seratch commented Jul 7, 2021

Just out of curiosity, is next_ a convention in Python? Rather than say nextMiddleware.

I think next_middleware is also fine but it may be a bit long (in comparison with other middleware args). As we use for syntax (for element in seq:) in most cases, it's rare to directly call next with an iterator. Having a kind of workaround name like this should make sense.

@seratch seratch merged commit dce45c5 into slackapi:main Jul 9, 2021
@seratch seratch deleted the issue-370-next_ branch July 9, 2021 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The next in middleware args overwrites Python built-in one
2 participants