**kwargs unexpectedly parses flags for later chained method
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
Research direction
Reproduce the behavior with the shown python -m fire command and the chained transform and do_something calls. Start by tracing argument parsing for chained method calls; done means flags after transform are passed to do_something instead of being absorbed into transform's kwargs, with coverage for this example.
Written by the indexing model from the issue text.
Description
Suppose we have the following program
from dataclasses import dataclass
@dataclass
class MyClass:
x: int
def transform(self, **kwargs):
return MyClass(self.x * kwargs.get("multiplier", 2))
def do_something(self, msg):
print(f"{msg}: {self.x}")
my_obj = MyClass(3)
And we call it with python -m fire my_module my_obj transform --multiplier=3 do_something --msg="test", then the --msg is parsed when calling transform into the kwargs dict. Then it errors saying --msg is missing. Can we instead support parsing flags before the next chained method call? The kwargs is useful for example, to transform the object in ways that only implementation classes know what to do.
My current workarounds are (1) pass msg as positional arg to do_something, (2) have do_something take **kwargs and call transform within it. Neither is ideal as (1) would surprise anyone who uses my code and (2) adds extra plumbing that could be avoided.
- Dominant language
- Python
- Stars
- 28.2k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
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.
More from google/python-fire
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
google/python-fire#693 ·
-
Release 0.7.2? Open
Difficulty 3/5 1-2 days Newbie friendliness 38/100
google/python-fire#698 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
google/python-fire#672 · 5 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
google/python-fire#665 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
google/python-fire#643 · 4 comments · 5 reactions ·
All issues in google/python-fire
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
use-agent-os/agent-os#3314 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
BasedHardware/omi#15662 · 1 comment ·
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
AiursoftWeb/AnduinOS-2#19 ·