-
Notifications
You must be signed in to change notification settings - Fork 427
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 support to pass args/kwargs to callables from Accessor #940
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fb159ce
Feature Request: Allow args/kwargs to be passed to a callable with a…
JordanHyatt 2865b77
after running black
JordanHyatt db93801
made updates per PR conversation
JordanHyatt 98f68b7
fixed test to accomondate the new design on passing callable args/kwargs
JordanHyatt ef3af42
fixed init to retain callable_args/kwargs if an Accessor object is pa…
JordanHyatt e8dd3ab
fixed bug that caused test to fail
JordanHyatt 57a2a80
black formatting update
JordanHyatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,17 @@ def test_short_circuit_dict(self): | |
|
||
self.assertEqual(Accessor("occupation__name").resolve(context), "Carpenter") | ||
|
||
def test_callable_args_kwargs(self): | ||
class MyClass: | ||
def method(self, *args, **kwargs): | ||
return args, kwargs | ||
|
||
callable_args = ("arg1", "arg2") | ||
callable_kwargs = {"kwarg1": "val1", "kwarg2": "val2"} | ||
obj = MyClass() | ||
result = Accessor("method", callable_args, callable_kwargs).resolve(obj) | ||
self.assertEqual(result, (callable_args, callable_kwargs)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Next step: supporting |
||
|
||
|
||
class AccessorTestModel(models.Model): | ||
foo = models.CharField(max_length=20) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure on the
callable_
-prefix, can we simplify this by just calling themself.args
andself.kwargs
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of like it being more verbose as it tells the user what those args and kwargs are being used for. If you disagree, I can make them be args and kwargs no problem. Another option is to not wild-card them and have the user pass them as a list/dict instead, this better indicates that they are "pass-through" args/kwargs. I am going to change it to the later and you let me know what you think