Skip to content

Commit 36a56c0

Browse files
authored
Continue upgrade of codebase to Python 3 (#556)
Obtained with pyupgrade, reverting any changes that remove a module we still depend on. `uv run pyupgrade **/**.py --py3-plus`
1 parent d320437 commit 36a56c0

11 files changed

+57
-57
lines changed

fire/__main__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ def import_from_file_path(path):
5454
"""
5555

5656
if not os.path.exists(path):
57-
raise IOError('Given file path does not exist.')
57+
raise OSError('Given file path does not exist.')
5858

5959
module_name = os.path.basename(path)
6060

6161
spec = util.spec_from_file_location(module_name, path)
6262

6363
if spec is None:
64-
raise IOError('Unable to load module from specified path.')
64+
raise OSError('Unable to load module from specified path.')
6565

6666
module = util.module_from_spec(spec) # pylint: disable=no-member
6767
spec.loader.exec_module(module) # pytype: disable=attribute-error
@@ -104,7 +104,7 @@ def import_module(module_or_filename):
104104
return import_from_file_path(module_or_filename)
105105

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

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

fire/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def __init__(self, code, component_trace):
199199
code: (int) Exit code for the Fire CLI.
200200
component_trace: (FireTrace) The trace for the Fire command.
201201
"""
202-
super(FireExit, self).__init__(code)
202+
super().__init__(code)
203203
self.trace = component_trace
204204

205205

fire/decorators_test.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from fire import testutils
2020

2121

22-
class NoDefaults(object):
22+
class NoDefaults:
2323
"""A class for testing decorated functions without default values."""
2424

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

4242

43-
class WithDefaults(object):
43+
class WithDefaults:
4444

4545
@decorators.SetParseFns(float)
4646
def example1(self, arg1=10):
@@ -51,14 +51,14 @@ def example2(self, arg1=10):
5151
return arg1, type(arg1)
5252

5353

54-
class MixedArguments(object):
54+
class MixedArguments:
5555

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

6060

61-
class PartialParseFn(object):
61+
class PartialParseFn:
6262

6363
@decorators.SetParseFns(arg1=str)
6464
def example4(self, arg1, arg2):
@@ -69,7 +69,7 @@ def example5(self, arg1, arg2):
6969
return arg1, arg2
7070

7171

72-
class WithKwargs(object):
72+
class WithKwargs:
7373

7474
@decorators.SetParseFns(mode=str, count=int)
7575
def example6(self, **kwargs):
@@ -79,7 +79,7 @@ def example6(self, **kwargs):
7979
)
8080

8181

82-
class WithVarArgs(object):
82+
class WithVarArgs:
8383

8484
@decorators.SetParseFn(str)
8585
def example7(self, arg1, arg2=None, *varargs, **kwargs): # pylint: disable=keyword-arg-before-vararg

fire/helptext.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ def _CreateAvailabilityLine(header, items,
767767
return indented_header + indented_items_text[len(indented_header):] + '\n'
768768

769769

770-
class ActionGroup(object):
770+
class ActionGroup:
771771
"""A group of actions of the same kind."""
772772

773773
def __init__(self, name, plural):

fire/helptext_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
class HelpTest(testutils.BaseTestCase):
2828

2929
def setUp(self):
30-
super(HelpTest, self).setUp()
30+
super().setUp()
3131
os.environ['ANSI_COLORS_DISABLED'] = '1'
3232

3333
def testHelpTextNoDefaults(self):

fire/inspectutils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from fire import docstrings
2323

2424

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

2828
def __init__(self, args=None, varargs=None, varkw=None, defaults=None,
@@ -229,7 +229,7 @@ def GetFileAndLine(component):
229229
try:
230230
unused_code, lineindex = inspect.findsource(component)
231231
lineno = lineindex + 1
232-
except (IOError, IndexError):
232+
except (OSError, IndexError):
233233
lineno = None
234234

235235
return filename, lineno
@@ -268,7 +268,7 @@ def Info(component):
268268
try:
269269
unused_code, lineindex = inspect.findsource(component)
270270
info['line'] = lineindex + 1
271-
except (TypeError, IOError):
271+
except (TypeError, OSError):
272272
info['line'] = None
273273

274274
if 'docstring' in info:

fire/main_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class MainModuleFileTest(testutils.BaseTestCase):
4343
"""Tests to verify correct import behavior for file executables."""
4444

4545
def setUp(self):
46-
super(MainModuleFileTest, self).setUp()
46+
super().setUp()
4747
self.file = tempfile.NamedTemporaryFile(suffix='.py') # pylint: disable=consider-using-with
4848
self.file.write(b'class Foo:\n def double(self, n):\n return 2 * n\n')
4949
self.file.flush()

fire/parser_fuzz_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def testDefaultParseValueFuzz(self, value):
5353
result = parser.DefaultParseValue(value)
5454
except TypeError:
5555
# It's OK to get a TypeError if the string has the null character.
56-
if u'\x00' in value:
56+
if '\x00' in value:
5757
return
5858
raise
5959
except MemoryError:

0 commit comments

Comments
 (0)