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

Add a nested_callable and getcallable util #417

Merged
merged 2 commits into from
Jun 16, 2022

Conversation

muellerzr
Copy link
Contributor

@muellerzr muellerzr commented Jun 15, 2022

nested_callable + getcallable

What does this add?

This PR adds a small util func of nested_callable. I was noticing this pattern being repeated a lot in fastai code:

someresult = getattr(obj, name, noop)(arg_a, arg_b, arg_c)

This util simplifies that code with a shorthand of nested_callable for nested attributes, and getcallable for non-nested attributes.

The new version looks like so:

someresult = nested_callable(obj, name)(arg_a, arg_b, arg_c)

(And with getcallable):

someresult = getcallable(obj, name)(arg_a, arg_b, arg_c)

cc @hamelsmu @jph00

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@muellerzr muellerzr changed the title Add a nested_callable util Add a nested_callable and getcallable util Jun 15, 2022
@hamelsmu hamelsmu merged commit 8598aa0 into fastai:master Jun 16, 2022
@hamelsmu
Copy link
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants