Closed dimitarOnGithub closed 2 weeks ago
Hi @dimitarOnGithub, thank you so much for taking the time to write this.
First off, apologies for any confusion, but when I read your comment on the closed issue, I was imagining slightly different use cases (that being said, I was fully unsure, so I asked you to share more details though).
The flexibility described here is something the bolt-python project would like to avoid, because, as you mentioned, customizations of listeners/middleware utilizing decorators could cause unexpected behavior and be difficult for humans to debug. Additionally, future enhancements on the bolt-python side may create conflicts.
If I understand your intention correctly, customization before running a listener is achievable with custom global (@app.use/middleware
) or listener-specific (a parameter to @app.event
) middleware. We would like to provide a single approach, fully controlled by the framework, to handle this.
I apologize again if this was a waste of your time, but I hope my response here clarifies things.
Hi @seratch ,
Please do not apologize! In fact, I should be the one doing that considering I didn't make my intention in the original comment clear enough, it'd have surely saved you the time you had to put aside to review this instead.
I completely understand, hence why I wanted to first provide all the details before jumping the gun and submitting a PR, I appreciate you taking the time to review my suggestion and provide feedback.
In my case, I'm already using some middleware to filter out and manipulate incoming requests, but as I use Bolt as a part of a bigger application, I wanted to be able to further abstract chunks of the requests and only provide listener functions with the bare minimum they need to perform a given request. Either way, it's not the end of the world for me and given the flexibility of the library, I'm sure I'll be able to find workarounds.
Again, thank you so much for your time and I can't wait to see what the future holds for Bolt!
Hi,
Opening this issue as a continuation of the conversation in #688, as I believe there's some design decisions that need to be made prior to reviewing and implementing the suggested changes.
Suggested Changes
My suggestion is changing the get_arg_names_of_callable to:
Checking if the listener function contains a
__wrapped__
attribute (populated by functools), allows the function to to instead inspect the wrapper itself.In the cases where the wrapper has not defined specific args injection (ie, wrapper signature is
def wrapper(*args, **kwargs)
), the length ofinspect.getfullargspec(func).args
is 0, in which case the function defaults to unwrapping and inspecting the listener itself.What does this achieve?
This change would allow users to have decorators that overwrite the arguments injection as defined by the listener functions, to illustrate;
With the current behavior, having a listener defined as:
tells Bolt to inject the
event
andsay
arguments when calling the listener function:Implementing the changes, would instead result in:
Or a custom decorator with additional arguments
While still retaining the fix of #689:
Assumptions and Downsides
Unfortunately, this change operates based on a few assumptions, each of which comes with downsides, and this is the reason why I believe it's best to talk through it first before submitting a PR straight off the bat; perhaps the shortcomings will outweigh the benefits and implementing this would not be a good fit for the Bolt's design principles and long-term maintenance.
@wraps
functionality as that wrapper is the one that populates the__wrapped__
argument;event
andclient
, while the next one expectsresp
andack
. The solution to this, of course, would be on the end user - they must be consistent in their decorators' definition and ensure that either all of them require the exact same args, or let the listener function be responsible for args injection while the decorators themselves only access the kwargs and modify them as required (in other words, the last code block above);Category (place an
x
in each of the[ ]
)Requirements
Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.