Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fire/helptext.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@ def _GetArgDefault(flag, spec):
for arg, default in zip(args_with_defaults, spec.defaults):
if arg == flag:
return repr(default)
if flag in spec.kwonlydefaults:
return repr(spec.kwonlydefaults[flag])
Comment on lines +527 to +528

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Consider handling the case where kwonlydefaults is None.

If spec.kwonlydefaults is None, this code will raise an AttributeError. It might be safer to check if kwonlydefaults is not None before checking if flag is in kwonlydefaults.

Suggested change
if flag in spec.kwonlydefaults:
return repr(spec.kwonlydefaults[flag])
if spec.kwonlydefaults and flag in spec.kwonlydefaults:
return repr(spec.kwonlydefaults[flag])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment helpful?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment type correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment area correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type of LLM test could this comment become?

  • 👍 - this comment is really good/important and we should always make it
  • 👎 - this comment is really bad and we should never make it
  • no reaction - don't turn this comment into an LLM test

return ''


Expand Down
12 changes: 12 additions & 0 deletions fire/helptext_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,18 @@ def testHelpTextKeywordOnlyArgumentsWithoutDefault(self):
self.assertIn('NAME\n double', output)
self.assertIn('FLAGS\n --count=COUNT (required)', output)

@testutils.skipIf(
six.PY2,
'Python 2 does not support required name-only arguments.')
def testHelpTextFunctionMixedDefaults(self):
component = tc.py3.HelpTextComponent().identity
t = trace.FireTrace(component, name='FunctionMixedDefaults')
output = helptext.HelpText(component, trace=t)
self.assertIn('NAME\n FunctionMixedDefaults', output)
self.assertIn('FunctionMixedDefaults <flags>', output)
self.assertIn('--alpha=ALPHA (required)', output)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Consider adding assertions for edge cases in testHelpTextFunctionMixedDefaults.

The test currently checks for the presence of flags with and without defaults. It would be beneficial to include assertions for edge cases such as missing flags or incorrect default values to ensure robustness.

Suggested change
self.assertIn('--alpha=ALPHA (required)', output)
self.assertIn('--alpha=ALPHA (required)', output)
self.assertIn('--beta=BETA\n Default: \'0\'', output)
self.assertNotIn('--gamma=GAMMA', output)
self.assertIn('--beta=BETA\n Default: \'1\'', output, msg="Check incorrect default for beta")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment helpful?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment type correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment area correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type of LLM test could this comment become?

  • 👍 - this comment is really good/important and we should always make it
  • 👎 - this comment is really bad and we should never make it
  • no reaction - don't turn this comment into an LLM test

self.assertIn('--beta=BETA\n Default: \'0\'', output)

def testHelpScreen(self):
component = tc.ClassWithDocstring()
t = trace.FireTrace(component, name='ClassWithDocstring')
Expand Down