Skip to content
Snippets Groups Projects

Add Options.apply_binds to allow applications to bind before calling user code

Merged Chris Burr requested to merge add-lbexec-apply_binds into master
All threads resolved!

In DaVinci a few cases have come up where code ends up looking like:

@configurable
def my_thing(process="MyDefault"):
    ...

Users then use this thing by running:

my_thing(process=options.process)

This gets a bit annoying when code starts being nested with there being multiple layers of

def my_func(process="MyDefault"):
    return my_other_func(process=process)

def my_other_func(process="MyDefault"):
    return my_thing(process=process)

A slightly better option is to make process a keyword only argument and bind:

@configurable
def my_thing(*, process):
    ...

def my_func():
    return my_other_func()

def my_other_func():
    return my_thing()

# Usage looks like
with my_thing.bind(process=options.process):
    my_func() 

This MR expands this slightly by allowing the application-specific Options class to automatically apply binds so the user code doesn't need to use bind. See DaVinci!731 (merged) for an example of this being used.

Merge request reports

Merge request pipeline #4551207 passed

Merge request pipeline passed for c62e4c77

Approved by

Merged by Rosen MatevRosen Matev 2 years ago (Oct 4, 2022 9:08am UTC)

Merge details

  • Changes merged into master with cc7c46c6.
  • Deleted the source branch.

Pipeline #4573555 passed

Pipeline passed for cc7c46c6 on master

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading