Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Merge branch 'master' into bug-fix-typing-package
  • Loading branch information
dbieber authored Sep 21, 2024
commit 2b0ebfad398c9ed62c2ee4553b9f2d23f7d85857
12 changes: 5 additions & 7 deletions fire/helptext.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def _CreateFlagItem(flag, docstring_info, spec, required=False,
# We need to handle the case where there is a default of None, but otherwise
# the argument has another type.
if arg_default == 'None' and not arg_type.startswith('Optional'):
arg_type = 'Optional[{}]'.format(arg_type)
arg_type = f'Optional[{arg_type}]'

arg_type = f'Type: {arg_type}' if arg_type else ''
available_space = max_str_length - len(arg_type)
Expand Down Expand Up @@ -524,12 +524,10 @@ def _GetArgType(arg, spec):
if arg in spec.annotations:
arg_type = spec.annotations[arg]
try:
if sys.version_info[0:2] >= (3, 3):
if isinstance(arg_type, typing._GenericAlias):
arg_type = repr(arg_type).replace('typing.', '')
return arg_type
return arg_type.__qualname__
return arg_type.__name__
if isinstance(arg_type, typing._GenericAlias):
arg_type = repr(arg_type).replace('typing.', '')
return arg_type
return arg_type.__qualname__
except AttributeError:
return repr(arg_type)
return ''
Expand Down
9 changes: 0 additions & 9 deletions fire/helptext_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ def testHelpTextFunctionWithTypesAndDefaultNone(self):
help_screen)
self.assertNotIn('NOTES', help_screen)

@testutils.skipIf(
sys.version_info[0:2] < (3, 5),
'Python < 3.5 does not support type hints.')
def testHelpTextFunctionWithTypesAndDefaultNoneFromTypingOptional(self):
component = (
tc.py3.WithDefaultsAndTypes().typing_optional_get_int) # pytype: disable=module-attr
Expand All @@ -170,9 +167,6 @@ def testHelpTextFunctionWithTypesAndDefaultNoneFromTypingOptional(self):
help_screen)
self.assertNotIn('NOTES', help_screen)

@testutils.skipIf(
sys.version_info[0:2] < (3, 5),
'Python < 3.5 does not support type hints.')
def testHelpTextFunctionWithTypesAndDefaultNoneFromTypingUnion(self):
component = (
tc.py3.WithDefaultsAndTypes().typing_union_get_int) # pytype: disable=module-attr
Expand All @@ -188,9 +182,6 @@ def testHelpTextFunctionWithTypesAndDefaultNoneFromTypingUnion(self):
help_screen)
self.assertNotIn('NOTES', help_screen)

@testutils.skipIf(
sys.version_info[0:2] < (3, 5),
'Python < 3.5 does not support type hints.')
def testHelpTextFunctionWithTypes(self):
component = tc.py3.WithTypes().double # pytype: disable=module-attr
help_screen = helptext.HelpText(
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.