-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix function-valued arguments (#119)
- Loading branch information
Showing
8 changed files
with
119 additions
and
2 deletions.
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import functions |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class _Dummy: | ||
@staticmethod | ||
def foo(): | ||
return 42 | ||
|
||
|
||
def search(a: int, b: list[int]) -> int: | ||
... | ||
|
||
|
||
def builtin_function_as_default_arg(func: type(len) = len): | ||
... | ||
|
||
|
||
def function_as_default_arg(func: type(search) = search): | ||
... | ||
|
||
|
||
def lambda_as_default_arg(callback=lambda val: 0): | ||
... | ||
|
||
|
||
def static_method_as_default_arg(callback=_Dummy.foo): | ||
... | ||
|
||
|
||
def arg_mix( | ||
a: int, | ||
b: float = 0.5, | ||
/, | ||
c: str = "", | ||
*args: int, | ||
x: int = 1, | ||
y=search, | ||
**kwargs: dict[int, str], | ||
): | ||
"""Mix of positional, kw and variadic args | ||
Note: | ||
The `inspect.getfullargspec` does not reflect presence | ||
of pos-only args separator (/) | ||
""" | ||
... |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
from . import functions | ||
|
||
__all__ = ["functions"] |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from __future__ import annotations | ||
|
||
import typing | ||
|
||
__all__ = [ | ||
"arg_mix", | ||
"builtin_function_as_default_arg", | ||
"function_as_default_arg", | ||
"lambda_as_default_arg", | ||
"search", | ||
"static_method_as_default_arg", | ||
] | ||
|
||
class _Dummy(object): | ||
@staticmethod | ||
def foo(): ... | ||
|
||
def arg_mix( | ||
a: int, | ||
b: float = 0.5, | ||
c: str = "", | ||
*args: int, | ||
x: int = 1, | ||
y=search, | ||
**kwargs: dict[int, str], | ||
): | ||
""" | ||
Mix of positional, kw and variadic args | ||
Note: | ||
The `inspect.getfullargspec` does not reflect presence | ||
of pos-only args separator (/) | ||
""" | ||
|
||
def builtin_function_as_default_arg(func: typing.Callable = ...): ... | ||
def function_as_default_arg(func: typing.Callable = search): ... | ||
def lambda_as_default_arg(callback=...): ... | ||
def search(a: int, b: list[int]) -> int: ... | ||
def static_method_as_default_arg(callback=_Dummy.foo): ... |