From e23adda65e9e006446cc3083248b4f71f56001ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=96zdemir?= Date: Mon, 13 Jul 2026 03:01:53 -0700 Subject: [PATCH] Fix chained kwarg scoping after positional args Fixes google/python-fire#379 Co-authored-by: Cursor --- fire/core.py | 3 +++ fire/fire_test.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/fire/core.py b/fire/core.py index 8e23e76b..632b212e 100644 --- a/fire/core.py +++ b/fire/core.py @@ -935,6 +935,9 @@ def _ParseKeywordArgs(args, fn_spec): remaining_kwargs.append(args[index + 1]) else: # not _IsFlag(argument) remaining_args.append(argument) + # Flags after a positional token belong to later commands in a chain. + remaining_args.extend(args[index + 1:]) + break return kwargs, remaining_kwargs, remaining_args diff --git a/fire/fire_test.py b/fire/fire_test.py index 99b4a7c6..9c0f6ec9 100644 --- a/fire/fire_test.py +++ b/fire/fire_test.py @@ -712,6 +712,27 @@ def testHelpKwargsDecorator(self): with self.assertRaisesFireExit(0): fire.Fire(tc.decorated_method, command=['--help']) + def testChainedKwargsWithSameParameterName(self): + class ChainKwargFoo: + def __init__(self): + self.log = [] + + def bar(self, param=0): + self.log.append(('bar', param)) + return self + + def baz(self, param=0): + self.log.append(('baz', param)) + return self + + def end(self): + return self.log + + obj = ChainKwargFoo() + result = fire.Fire( + obj, command=['bar', '--param=3', 'baz', '--param=5', 'end']) + self.assertEqual(result, [('bar', 3), ('baz', 5)]) + def testFireAsyncio(self): self.assertEqual(fire.Fire(tc.py3.WithAsyncio, command=['double', '--count', '10']), 20)