Skip to content

Commit

Permalink
Remove sys.version_info checks (#542)
Browse files Browse the repository at this point in the history
* Remove sys.version_info checks where no longer needed
  • Loading branch information
dbieber authored Sep 20, 2024
1 parent 5d0706d commit b13c13b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 38 deletions.
25 changes: 6 additions & 19 deletions fire/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""

import importlib
from importlib import util
import os
import sys

Expand Down Expand Up @@ -57,27 +58,13 @@ def import_from_file_path(path):

module_name = os.path.basename(path)

if sys.version_info.major == 3 and sys.version_info.minor < 5:
loader = importlib.machinery.SourceFileLoader( # pylint: disable=no-member
fullname=module_name,
path=path,
)
spec = util.spec_from_file_location(module_name, path)

module = loader.load_module(module_name) # pylint: disable=deprecated-method
if spec is None:
raise IOError('Unable to load module from specified path.')

elif sys.version_info.major == 3:
from importlib import util # pylint: disable=g-import-not-at-top,import-outside-toplevel,no-name-in-module
spec = util.spec_from_file_location(module_name, path)

if spec is None:
raise IOError('Unable to load module from specified path.')

module = util.module_from_spec(spec) # pylint: disable=no-member
spec.loader.exec_module(module) # pytype: disable=attribute-error

else:
import imp # pylint: disable=g-import-not-at-top,import-outside-toplevel,deprecated-module,import-error
module = imp.load_source(module_name, path)
module = util.module_from_spec(spec) # pylint: disable=no-member
spec.loader.exec_module(module) # pytype: disable=attribute-error

return module, module_name

Expand Down
2 changes: 0 additions & 2 deletions fire/fire_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,6 @@ def testClassWithInvalidProperty(self):
fire.Fire(tc.InvalidProperty, command=['double', '10']), 20
)

@testutils.skipIf(sys.version_info[0:2] <= (3, 4),
'Cannot inspect wrapped signatures in Python 2 or 3.4.')
def testHelpKwargsDecorator(self):
# Issue #190, follow the wrapped method instead of crashing.
with self.assertRaisesFireExit(0):
Expand Down
5 changes: 1 addition & 4 deletions fire/helptext.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import collections
import itertools
import sys

from fire import completion
from fire import custom_descriptions
Expand Down Expand Up @@ -533,9 +532,7 @@ def _GetArgType(arg, spec):
if arg in spec.annotations:
arg_type = spec.annotations[arg]
try:
if sys.version_info[0:2] >= (3, 3):
return arg_type.__qualname__
return arg_type.__name__
return arg_type.__qualname__
except AttributeError:
# Some typing objects, such as typing.Union do not have either a __name__
# or __qualname__ attribute.
Expand Down
13 changes: 0 additions & 13 deletions fire/helptext_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""Tests for the helptext module."""

import os
import sys
import textwrap

from fire import formatting
Expand Down Expand Up @@ -124,9 +123,6 @@ def testHelpTextFunctionWithKwargsAndDefaults(self):
'Additional undocumented flags may also be accepted.',
help_screen)

@testutils.skipIf(
sys.version_info[0:2] < (3, 5),
'Python < 3.5 does not support type hints.')
def testHelpTextFunctionWithDefaultsAndTypes(self):
component = (
tc.py3.WithDefaultsAndTypes().double) # pytype: disable=module-attr
Expand All @@ -141,9 +137,6 @@ def testHelpTextFunctionWithDefaultsAndTypes(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 testHelpTextFunctionWithTypesAndDefaultNone(self):
component = (
tc.py3.WithDefaultsAndTypes().get_int) # pytype: disable=module-attr
Expand All @@ -159,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 testHelpTextFunctionWithTypes(self):
component = tc.py3.WithTypes().double # pytype: disable=module-attr
help_screen = helptext.HelpText(
Expand All @@ -177,9 +167,6 @@ def testHelpTextFunctionWithTypes(self):
'NOTES\n You can also use flags syntax for POSITIONAL ARGUMENTS',
help_screen)

@testutils.skipIf(
sys.version_info[0:2] < (3, 5),
'Python < 3.5 does not support type hints.')
def testHelpTextFunctionWithLongTypes(self):
component = tc.py3.WithTypes().long_type # pytype: disable=module-attr
help_screen = helptext.HelpText(
Expand Down
1 change: 1 addition & 0 deletions fire/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
else:
_StrNode = ast.Constant


def CreateParser():
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--verbose', '-v', action='store_true')
Expand Down

0 comments on commit b13c13b

Please sign in to comment.