-
-
Notifications
You must be signed in to change notification settings - Fork 60
feat: support for partialmethod #665
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
8b94b30
c440f4c
828a7c3
ba941d4
66b7ef6
5571ffb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import inspect | ||
| import xml.dom | ||
| from calendar import Calendar | ||
| from functools import partialmethod | ||
| from random import shuffle | ||
| from typing import Any, Callable, Dict, List, Optional, Union | ||
| from unittest.mock import patch | ||
|
|
@@ -33,6 +34,8 @@ def method_a(self, pma1: int, pma2: float, kma1: str = "x"): | |
| kma1: help for kma1 | ||
| """ | ||
|
|
||
| partial_method_a = partialmethod(method_a, pma1=1, pma2=0.5) | ||
|
|
||
|
|
||
| class ClassB(ClassA): | ||
| def __init__(self, pkb1: str, kb1: int = 3, kb2: str = "4", **kwargs): | ||
|
|
@@ -899,6 +902,14 @@ def test_get_params_some_ignored(): | |
| assert_params(get_params(func_given_kwargs), ["p", "p1"], help=False) | ||
|
|
||
|
|
||
| # test partial method | ||
mauvilsa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 commentThe 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 |
||
| with source_unavailable(): | ||
| assert_params(get_params(ClassA, "partial_method_a"), ["pma1", "pma2", "kma1"]) | ||
|
|
||
|
|
||
| # unsupported cases | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.