python-fire icon indicating copy to clipboard operation
python-fire copied to clipboard

Everything after the `#` character gets stripped down from string argument

Open nazarewk opened this issue 7 months ago • 3 comments

This is pretty self-explanatory:

> python -c 'import fire; fire.Fire(lambda x: print(repr(x)))' 'qgm#123'
'qgm'

nazarewk avatar Jul 22 '25 11:07 nazarewk

Isn't this the shell interpreting it as a comment? Have you tried breaking out the comment symbol? qgm\#123

Tgenz1213 avatar Aug 16 '25 20:08 Tgenz1213

doesn't help much:

> python -c 'import fire; fire.Fire(lambda x: print(repr(x)))' 'qgm\#123'
'qgm\\#123'
> python -c 'import fire; fire.Fire(lambda x: print(repr(x)))' "qgm\#123"
'qgm\\#123'

nazarewk avatar Aug 17 '25 06:08 nazarewk

It seems intentional currently. It's because the ast library is used to interpret the argument as a literal instead of a string. Can you try wrapping your argument in double and single quotes like the first test case here?

https://github.com/google/python-fire/blob/master/fire/parser_test.py lines 120-123:

def testDefaultParseValueComments(self):
  self.assertEqual(parser.DefaultParseValue('"0#comments"'), '0#comments')
  # Comments are stripped. This behavior may change in the future.
  self.assertEqual(parser.DefaultParseValue('0#comments'), 0)

Tgenz1213 avatar Aug 17 '25 11:08 Tgenz1213