Skip to content

Commit

Permalink
Continue upgrade of codebase to Python 3 (#556)
Browse files Browse the repository at this point in the history
Obtained with pyupgrade, reverting any changes that remove a module we still depend on.
`uv run pyupgrade **/**.py --py3-plus`
  • Loading branch information
dbieber authored Sep 21, 2024
1 parent d320437 commit 36a56c0
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 57 deletions.
6 changes: 3 additions & 3 deletions fire/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ def import_from_file_path(path):
"""

if not os.path.exists(path):
raise IOError('Given file path does not exist.')
raise OSError('Given file path does not exist.')

module_name = os.path.basename(path)

spec = util.spec_from_file_location(module_name, path)

if spec is None:
raise IOError('Unable to load module from specified path.')
raise OSError('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
Expand Down Expand Up @@ -104,7 +104,7 @@ def import_module(module_or_filename):
return import_from_file_path(module_or_filename)

if os.path.sep in module_or_filename: # Use / to detect if it was a filename.
raise IOError('Fire was passed a filename which could not be found.')
raise OSError('Fire was passed a filename which could not be found.')

return import_from_module_name(module_or_filename) # Assume it's a module.

Expand Down
2 changes: 1 addition & 1 deletion fire/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def __init__(self, code, component_trace):
code: (int) Exit code for the Fire CLI.
component_trace: (FireTrace) The trace for the Fire command.
"""
super(FireExit, self).__init__(code)
super().__init__(code)
self.trace = component_trace


Expand Down
12 changes: 6 additions & 6 deletions fire/decorators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from fire import testutils


class NoDefaults(object):
class NoDefaults:
"""A class for testing decorated functions without default values."""

@decorators.SetParseFns(count=int)
Expand All @@ -40,7 +40,7 @@ def double(count):
return 2 * count


class WithDefaults(object):
class WithDefaults:

@decorators.SetParseFns(float)
def example1(self, arg1=10):
Expand All @@ -51,14 +51,14 @@ def example2(self, arg1=10):
return arg1, type(arg1)


class MixedArguments(object):
class MixedArguments:

@decorators.SetParseFns(float, arg2=str)
def example3(self, arg1, arg2):
return arg1, arg2


class PartialParseFn(object):
class PartialParseFn:

@decorators.SetParseFns(arg1=str)
def example4(self, arg1, arg2):
Expand All @@ -69,7 +69,7 @@ def example5(self, arg1, arg2):
return arg1, arg2


class WithKwargs(object):
class WithKwargs:

@decorators.SetParseFns(mode=str, count=int)
def example6(self, **kwargs):
Expand All @@ -79,7 +79,7 @@ def example6(self, **kwargs):
)


class WithVarArgs(object):
class WithVarArgs:

@decorators.SetParseFn(str)
def example7(self, arg1, arg2=None, *varargs, **kwargs): # pylint: disable=keyword-arg-before-vararg
Expand Down
2 changes: 1 addition & 1 deletion fire/helptext.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def _CreateAvailabilityLine(header, items,
return indented_header + indented_items_text[len(indented_header):] + '\n'


class ActionGroup(object):
class ActionGroup:
"""A group of actions of the same kind."""

def __init__(self, name, plural):
Expand Down
2 changes: 1 addition & 1 deletion fire/helptext_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class HelpTest(testutils.BaseTestCase):

def setUp(self):
super(HelpTest, self).setUp()
super().setUp()
os.environ['ANSI_COLORS_DISABLED'] = '1'

def testHelpTextNoDefaults(self):
Expand Down
6 changes: 3 additions & 3 deletions fire/inspectutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from fire import docstrings


class FullArgSpec(object):
class FullArgSpec:
"""The arguments of a function, as in Python 3's inspect.FullArgSpec."""

def __init__(self, args=None, varargs=None, varkw=None, defaults=None,
Expand Down Expand Up @@ -229,7 +229,7 @@ def GetFileAndLine(component):
try:
unused_code, lineindex = inspect.findsource(component)
lineno = lineindex + 1
except (IOError, IndexError):
except (OSError, IndexError):
lineno = None

return filename, lineno
Expand Down Expand Up @@ -268,7 +268,7 @@ def Info(component):
try:
unused_code, lineindex = inspect.findsource(component)
info['line'] = lineindex + 1
except (TypeError, IOError):
except (TypeError, OSError):
info['line'] = None

if 'docstring' in info:
Expand Down
2 changes: 1 addition & 1 deletion fire/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MainModuleFileTest(testutils.BaseTestCase):
"""Tests to verify correct import behavior for file executables."""

def setUp(self):
super(MainModuleFileTest, self).setUp()
super().setUp()
self.file = tempfile.NamedTemporaryFile(suffix='.py') # pylint: disable=consider-using-with
self.file.write(b'class Foo:\n def double(self, n):\n return 2 * n\n')
self.file.flush()
Expand Down
2 changes: 1 addition & 1 deletion fire/parser_fuzz_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def testDefaultParseValueFuzz(self, value):
result = parser.DefaultParseValue(value)
except TypeError:
# It's OK to get a TypeError if the string has the null character.
if u'\x00' in value:
if '\x00' in value:
return
raise
except MemoryError:
Expand Down
Loading

0 comments on commit 36a56c0

Please sign in to comment.