Giter Club home page Giter Club logo

Comments (5)

carl0FF avatar carl0FF commented on June 12, 2024 1

I see. I guess your suggestion of interface makes sense from a pythonic perspective. I have 2 concerns though if we go with it:

  1. if we want to add it as a non-breaking change, the interface will be ambiguous because there will be two ways of calling run(), which may generate confusion.
  2. if we want to avoid the above situation, we should replace the current method with your suggestion and release a new version of the library. This will imply updating a fair amount of code and documentation
    What are your thoughts?

from pyfailsafe.

carl0FF avatar carl0FF commented on June 12, 2024

Could you provide an example that illustrates how your proposal would look like?

from pyfailsafe.

rmariano avatar rmariano commented on June 12, 2024

From a users' perspective I imagine the previous example could work like this

return await self.failsafe.run(self._request, url) 

and speaking in terms of the implementation, on a very high level, I imagine the run coroutine at

async def run(self, callable):
can be adapted as:

async def run(self, callable, *args, **kwargs):
    callable = partial(callable, *args, **kwargs)

from pyfailsafe.

rmariano avatar rmariano commented on June 12, 2024

Technically, there will still be only one way of calling the function, which is passing the callable and then its arguments. It just so happens that if the user wraps the original call, there will be no extra arguments to pass, as the function was already partially applied.

I forgot to mention before but because of this, the proposed change is backwards compatible (the calls already using the lambda: ... should still work).

The fact that the signature contains *args, **kwargs should already signal that they're optional parameters, and belong to the wrapped callable. Considering this is customary in Python, some users were probably already expecting this kind interface.

In any case, this change merits a new version of the library.

As for the examples and documentation, I would only extend them to mention that, in addition to how users were already using the feature, this new version allows passing the parameters explicitly.

It seems that, with this proposal, there will be three possible cases:

  1. Functions that already take no parameters, can be used directly --> This doesn't change
async def my_func(): ....
my_failsafe.run(my_func)
  1. Functions that take parameters, and these are wrapped (current use case) --> This will still work.
async def my_func(x): ...
my_failsafe.run(lambda: my_func(1))
  1. The new interface
async def my_func(x): ...
my_failsafe.run(my_func, 1)

So let's say [2] is what we already have in the docs and examples, I'd mention in the docs that starting from version 0.5.0 (as of this writing), the format in [3] is also accepted.

The idea is to present a slighly simpler interface, without needing the extra-wrapping before calling the function.

from pyfailsafe.

carl0FF avatar carl0FF commented on June 12, 2024

My main concern in this case is having 2 ways of doing the same thing, i.e. calling the callable with parameters. I'd prefer to have a single, well documented one - being it your proposed new interface.

from pyfailsafe.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.