[Bug]: `namespaced_function`/`alias_function` drop kwdefaults
Open
Beginner friendly
Nobody has claimed this yet.
bug
needs-triage
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
What happened?
Having used salt.utils.functools.namespaced_function (or alias_function) to copy a function that has keyword-only arguments with defaults and calling the copy without providing a value for these yields a TypeError. Example:
from salt.utils.functools import namespaced_function, alias_function
def foo(bar=None, *_, baz=None):
pass
foo_ns = namespaced_function(foo, globals())
foo_alias = alias_function(foo, "foo_alias")
foo()
foo_ns()
# Traceback (most recent call last):
# File "<python-input-13>", line 1, in <module>
# foo_ns()
# ~~~~~~^^
# TypeError: foo() missing 1 required keyword-only argument: 'baz'
foo_alias()
# Traceback (most recent call last):
# File "<python-input-14>", line 1, in <module>
# foo_ns()
# ~~~~~~^^
# TypeError: foo() missing 1 required keyword-only argument: 'baz'
Type of salt install
Official deb
Major version
3006.x
What supported OS are you seeing the problem on? Can select multiple. (If bug appears on an unsupported OS, please open a GitHub Discussion instead)
ubuntu-24.04
salt --versions-report output
Current HEAD of 3006.x
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading salt.utils.functools.namespaced_function and alias_function, then reproduce the reported calls with a keyword-only default such as baz=None. Done means both copied functions retain the original keyword defaults and the regression tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100