Code Monkey home page Code Monkey logo

Comments (11)

vinci1it2000 avatar vinci1it2000 commented on July 29, 2024

I prefer to play with the object type then add two extra kw...

example:

inputs=('a', 'b') 

is equivalent to

inputs={'a':'a','b':'b'}

from schedula.

ankostis avatar ankostis commented on July 29, 2024

And can you combine both?

from schedula.

vinci1it2000 avatar vinci1it2000 commented on July 29, 2024

what do you mean?

from schedula.

ankostis avatar ankostis commented on July 29, 2024

Specify both auto-mapped names and explicitly mapped ones, in the same add_dispatcher() invocation?

from schedula.

vinci1it2000 avatar vinci1it2000 commented on July 29, 2024

I want to avoid extra kws. I can build an utility like:

def auto_dict(*args, **kw):
    return sh.combine_dict(kw, base={k: k for k in args}) 

what do you think?

from schedula.

ankostis avatar ankostis commented on July 29, 2024

In practical terms, what you suggest achieves the same, but with more code/dependencies.

What's the reason not to add new kwds?

from schedula.

vinci1it2000 avatar vinci1it2000 commented on July 29, 2024

I have to add for both inputs and outputs kw, while the utl is solving both (so less code).

from schedula.

ankostis avatar ankostis commented on July 29, 2024

Well, that's a valid reason.

Let's compare the two:

from utils import auto_dict

add_dispatcher(
               dsp, 
               auto_dict('a', 'b', c='c_renamed'), 
               auto_dict('out_a', 'out_b', out_c='out_c_renamed'))

vs

add_dispatcher(
               dsp, 
               {'b': 'out_b_renamed'}, 
               {'out_b': 'out_b_renamed'}, 
               inp_names=['a', 'b'], 
               out_names=['a_out', 'b_out']))

I like the use of python's kwd syntax.
Note though that most of the time, at least in co2mpas code, it would be only the last 2 kwds that are used - no that many renamed params.

But with an intermediate function you loose the opportunity to invoke sub-dispatchers directly from configuration text-files, at least not without requiring the use of that helper function, in which case, why not add the kwds anyway?

In any case, auto_dict is totally opaque name to tell what it does, and hard to remember with all other auto-magic dict functions.
I would call it identical_kv_dict or even shorter idkvmap.

from schedula.

ankostis avatar ankostis commented on July 29, 2024

Of course the optimal would be, since most of the times only the identical kvs are used, add a new method that has the inp_names/out_names kwds as the first args of the new methods, and move inputs/outputs args at the end.
So in a nutshell, reverse the meaning of those two.

That's refactoring for DRY.

from schedula.

ankostis avatar ankostis commented on July 29, 2024

Something like this?

add_dispatcher(
               dsp, 
               ['a', 'b', {'c'='c_renamed'}], 
               ('out_a', 'out_b', dict(out_c='out_c_renamed'))

And these should be invalid:

add_dispatcher(
               dsp, 
               'abc',  # valid: a sequence 
               ('out_a', 'out_b', dict(out_c='out_c_renamed'), 'd')  # INVALID: trailing element

from schedula.

vinci1it2000 avatar vinci1it2000 commented on July 29, 2024

Implementation example:

d.add_dispatcher(dsp, inputs=('a', {'b': 'c'}, 'd', {'e': 'f', 'g': 'h'})

equivalent:

d.add_dispatcher(dsp, inputs={'a': 'a', 'b': 'c', 'd': 'd', 'e': 'f', 'g': 'h'})

from schedula.

Related Issues (19)

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.