-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
feat: support for partialmethod #665
base: main
Are you sure you want to change the base?
feat: support for partialmethod #665
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## main #665 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 6654 6670 +16
=========================================
+ Hits 6654 6670 +16 ☔ View full report in Codecov by Sentry. |
for more information, see https://pre-commit.ci
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 can't think of a reason why not to support this. Please go ahead and write the unit tests.
I was able to add support for The options would be to add a subsection in |
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 was able to add support for partialmethod and added a test for it. For partial functions and classes it's a bit trickier since they are dynamic and it seems the parameter resolver is expecting static objects for the most part.
What was the reason you came to know that partials didn't work? I would guess it was because you needed it for some use case. If it was only for partialmethod
, then what is implemented now already works and is a new feature. If you really want partial
to also work, later I can take a look.
For classes the main reason is that For reference, my use case was to create partial classes. I got around the limitations by using
|
@@ -899,6 +902,13 @@ def test_get_params_some_ignored(): | |||
assert_params(get_params(func_given_kwargs), ["p", "p1"], help=False) | |||
|
|||
|
|||
def test_partialmethod(): | |||
ClassA.partial_method_a = partialmethod(ClassA.method_a, pma1=1, pma2=0.5) | |||
assert_params(get_params(ClassA, "partial_method_a"), ["pma1", "pma2", "kma1"]) |
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.
Looking again at this test now I think there are things missing. The partial doesn't change the list of parameter names. But it does change the defaults. Are the defaults correctly inferred by a parser? If not, then it doesn't really work as expected. So this should be tested.
And another thing that could be considered missing is that a method could be set as default to a callable. For this --print_config
should serialize this default into an import path string. And this import path when used in a config, should be correctly deserialize into the partial method object.
For partial functions and classes being dynamic, the import path would also be a problem. If a partial function is saved at the top level of a module in a variable, from the partial function object alone can it be determined what its import path should be? |
What does this PR do?
Adds support for functools.partial and functools.partialmethod and closes #664
Still need to write tests and update documentation but would like wait for @mauvilsa to weigh in to see if the idea makes sense.
Before submitting