From 54aaeab06c04f89965f0d206086aea72a3a4b1b0 Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Sun, 15 Oct 2023 01:42:25 -0400 Subject: [PATCH] Update syntax with pyupgrade --- av/datasets.py | 6 +++--- av/deprecation.py | 6 +++--- docs/api/error_table.py | 5 ++--- docs/conf.py | 15 +++++++-------- docs/development/includes.py | 20 ++++++++++---------- examples/basics/parse.py | 2 +- examples/basics/save_keyframes.py | 2 +- examples/basics/thread_type.py | 4 ++-- scratchpad/audio.py | 2 +- scratchpad/audio_player.py | 2 +- scratchpad/cctx_decode.py | 2 +- scratchpad/decode.py | 8 ++++---- scratchpad/filter_audio.py | 6 +++--- scratchpad/frame_seek_example.py | 14 +++++++------- scratchpad/glproxy.py | 2 +- scratchpad/qtproxy.py | 2 +- scratchpad/resource_use.py | 2 +- scratchpad/second_seek_example.py | 14 +++++++------- scratchpad/seekmany.py | 3 +-- scripts/fetch-vendor.py | 2 +- tests/common.py | 14 +++++++------- tests/test_codec_context.py | 9 +++------ tests/test_deprecation.py | 4 ++-- tests/test_enums.py | 2 +- tests/test_errors.py | 4 ++-- tests/test_python_io.py | 4 ++-- 26 files changed, 75 insertions(+), 81 deletions(-) diff --git a/av/datasets.py b/av/datasets.py index 3324ce0bc..bf610b89b 100644 --- a/av/datasets.py +++ b/av/datasets.py @@ -62,7 +62,7 @@ def cached_download(url, name): clean_name = os.path.normpath(name) if clean_name != name: - raise ValueError("{} is not normalized.".format(name)) + raise ValueError(f"{name} is not normalized.") for dir_ in iter_data_dirs(): path = os.path.join(dir_, name) @@ -72,11 +72,11 @@ def cached_download(url, name): dir_ = next(iter_data_dirs(True)) path = os.path.join(dir_, name) - log.info("Downloading {} to {}".format(url, path)) + log.info(f"Downloading {url} to {path}") response = urlopen(url) if response.getcode() != 200: - raise ValueError("HTTP {}".format(response.getcode())) + raise ValueError(f"HTTP {response.getcode()}") dir_ = os.path.dirname(path) try: diff --git a/av/deprecation.py b/av/deprecation.py index 1e0cbb317..c89f1a761 100644 --- a/av/deprecation.py +++ b/av/deprecation.py @@ -21,7 +21,7 @@ class MethodDeprecationWarning(AVDeprecationWarning): warnings.filterwarnings("default", "", AVDeprecationWarning) -class renamed_attr(object): +class renamed_attr: """Proxy for renamed attributes (or methods) on classes. Getting and setting values will be redirected to the provided name, @@ -68,14 +68,14 @@ def __set__(self, instance, value): setattr(instance, self.new_name, value) -class method(object): +class method: def __init__(self, func): functools.update_wrapper(self, func, ("__name__", "__doc__")) self.func = func def __get__(self, instance, cls): warning = MethodDeprecationWarning( - "{}.{} is deprecated.".format(cls.__name__, self.func.__name__) + f"{cls.__name__}.{self.func.__name__} is deprecated." ) warnings.warn(warning, stacklevel=2) return self.func.__get__(instance, cls) diff --git a/docs/api/error_table.py b/docs/api/error_table.py index e67b9f40b..2fe029073 100644 --- a/docs/api/error_table.py +++ b/docs/api/error_table.py @@ -1,4 +1,3 @@ - import av @@ -21,8 +20,8 @@ rows.append(( #'{} ({})'.format(enum.tag, code), - '``av.{}``'.format(cls.__name__), - '``av.error.{}``'.format(enum.name), + f'``av.{cls.__name__}``', + f'``av.error.{enum.name}``', enum.strerror, )) diff --git a/docs/conf.py b/docs/conf.py index cc97c4397..bf5fb4b0b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # PyAV documentation build configuration file, created by # sphinx-quickstart on Fri Dec 7 22:13:16 2012. @@ -29,7 +28,7 @@ if sphinx.version_info < (1, 8): - print("Sphinx {} is too old; we require >= 1.8.".format(sphinx.__version__), file=sys.stderr) + print(f"Sphinx {sphinx.__version__} is too old; we require >= 1.8.", file=sys.stderr) exit(1) @@ -72,8 +71,8 @@ master_doc = 'index' # General information about the project. -project = u'PyAV' -copyright = u'2017, Mike Boers' +project = 'PyAV' +copyright = '2017, Mike Boers' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -350,8 +349,8 @@ def makerow(*texts): return row thead += makerow( - '{} Attribute'.format(cls.__name__) if cls else None, - '{} Name'.format(enum.__name__), + f'{cls.__name__} Attribute' if cls else None, + f'{enum.__name__} Name', 'Flag Value', 'Meaning in FFmpeg', ) @@ -371,7 +370,7 @@ def makerow(*texts): continue attr = None - value = '0x{:X}'.format(item.value) + value = f'0x{item.value:X}' doc = item.__doc__ or '-' @@ -420,7 +419,7 @@ def doxylink_create_handler(app, file_name, url_base): parent = parent_map.get(node) parent_name = parent.find('name') if parent else None if parent_name is not None: - name = '{}.{}'.format(parent_name.text, name) + name = f'{parent_name.text}.{name}' filenode = node.find('filename') if filenode is not None: diff --git a/docs/development/includes.py b/docs/development/includes.py index 8f350a81e..e4cb45e3b 100644 --- a/docs/development/includes.py +++ b/docs/development/includes.py @@ -16,7 +16,7 @@ class Visitor(TreeVisitor): def __init__(self, state=None): - super(Visitor, self).__init__() + super().__init__() self.state = dict(state or {}) self.events = [] @@ -160,14 +160,14 @@ def inspect_member(node, name_prefix=''): anchorfile = node.find('anchorfile').text anchor = node.find('anchor').text - url = '%s/%s#%s' % (doxygen_base, anchorfile, anchor) + url = '{}/{}#{}'.format(doxygen_base, anchorfile, anchor) doxygen[name] = {'url': url} if node.attrib['kind'] == 'function': ret_type = node.find('type').text arglist = node.find('arglist').text - sig = '%s %s%s' % (ret_type, name, arglist) + sig = '{} {}{}'.format(ret_type, name, arglist) doxygen[name]['sig'] = sig for struct in root.iter('compound'): @@ -190,7 +190,7 @@ def inspect_member(node, name_prefix=''): try: events = extract(path) except Exception as e: - print(" %s in %s" % (e.__class__.__name__, path), file=sys.stderr) + print(" {} in {}".format(e.__class__.__name__, path), file=sys.stderr) print(" %s" % e, file=sys.stderr) continue for event in events: @@ -249,7 +249,7 @@ def inspect_member(node, name_prefix=''): elif event['type'] == 'variable': struct = event.get('struct') if struct: - event['_headline'] = '.. c:member:: %s %s' % (event['vartype'], event['name']) + event['_headline'] = '.. c:member:: {} {}'.format(event['vartype'], event['name']) event['_sort_key'] = 1.1 else: event['_headline'] = '.. c:var:: %s' % event['name'] @@ -258,14 +258,14 @@ def inspect_member(node, name_prefix=''): elif event['type'] == 'struct': event['_headline'] = '.. c:type:: struct %s' % event['name'] event['_sort_key'] = 1 - event['_doxygen_url'] = '%s/struct%s.html' % (doxygen_base, event['name']) + event['_doxygen_url'] = '{}/struct{}.html'.format(doxygen_base, event['name']) else: print('Unknown event type %s' % event['type'], file=sys.stderr) name = event['name'] if event.get('struct'): - name = '%s.%s' % (event['struct'], name) + name = '{}.{}'.format(event['struct'], name) # Doxygen URLs event.setdefault('_doxygen_url', doxygen.get(name, {}).get('url')) @@ -285,13 +285,13 @@ def inspect_member(node, name_prefix=''): prefix = '.'.join(chunks) + '.' if chunks else '' if ref.get('property'): - ref_pairs.append((ref['property'], ':attr:`%s%s`' % (prefix, ref['property']))) + ref_pairs.append((ref['property'], ':attr:`{}{}`'.format(prefix, ref['property']))) elif ref.get('function'): name = ref['function'] if name in ('__init__', '__cinit__', '__dealloc__'): - ref_pairs.append((name, ':class:`%s%s <%s>`' % (prefix, name, prefix.rstrip('.')))) + ref_pairs.append((name, ':class:`{}{} <{}>`'.format(prefix, name, prefix.rstrip('.')))) else: - ref_pairs.append((name, ':func:`%s%s`' % (prefix, name))) + ref_pairs.append((name, ':func:`{}{}`'.format(prefix, name))) else: continue diff --git a/examples/basics/parse.py b/examples/basics/parse.py index 2d313cb3f..04f4528ef 100644 --- a/examples/basics/parse.py +++ b/examples/basics/parse.py @@ -33,7 +33,7 @@ chunk = fh.read(1 << 16) packets = codec.parse(chunk) - print("Parsed {} packets from {} bytes:".format(len(packets), len(chunk))) + print(f"Parsed {len(packets)} packets from {len(chunk)} bytes:") for packet in packets: diff --git a/examples/basics/save_keyframes.py b/examples/basics/save_keyframes.py index 1169c153a..3de25f84a 100644 --- a/examples/basics/save_keyframes.py +++ b/examples/basics/save_keyframes.py @@ -14,6 +14,6 @@ # We use `frame.pts` as `frame.index` won't make must sense with the `skip_frame`. frame.to_image().save( - "night-sky.{:04d}.jpg".format(frame.pts), + f"night-sky.{frame.pts:04d}.jpg", quality=80, ) diff --git a/examples/basics/thread_type.py b/examples/basics/thread_type.py index 2fa7562c9..51c23a79e 100644 --- a/examples/basics/thread_type.py +++ b/examples/basics/thread_type.py @@ -39,5 +39,5 @@ container.close() -print("Decoded with default threading in {:.2f}s.".format(default_time)) -print("Decoded with auto threading in {:.2f}s.".format(auto_time)) +print(f"Decoded with default threading in {default_time:.2f}s.") +print(f"Decoded with auto threading in {auto_time:.2f}s.") diff --git a/scratchpad/audio.py b/scratchpad/audio.py index addae0915..4b91a0621 100644 --- a/scratchpad/audio.py +++ b/scratchpad/audio.py @@ -92,7 +92,7 @@ def print_data(frame): try: for frame in frames: ffplay.stdin.write(bytes(frame.planes[0])) - except IOError as e: + except OSError as e: print(e) exit() diff --git a/scratchpad/audio_player.py b/scratchpad/audio_player.py index 8322a3206..32e24be44 100644 --- a/scratchpad/audio_player.py +++ b/scratchpad/audio_player.py @@ -57,7 +57,7 @@ def decode_iter(): bytes_buffered = output.bufferSize() - output.bytesFree() us_processed = output.processedUSecs() us_buffered = 1000000 * bytes_buffered / (2 * 16 / 8) / 48000 - print('pts: %.3f, played: %.3f, buffered: %.3f' % (frame.time or 0, us_processed / 1000000.0, us_buffered / 1000000.0)) + print('pts: {:.3f}, played: {:.3f}, buffered: {:.3f}'.format(frame.time or 0, us_processed / 1000000.0, us_buffered / 1000000.0)) data = bytes(frame.planes[0]) diff --git a/scratchpad/cctx_decode.py b/scratchpad/cctx_decode.py index bdb6724f4..b1997df0d 100644 --- a/scratchpad/cctx_decode.py +++ b/scratchpad/cctx_decode.py @@ -13,7 +13,7 @@ print(cc) -fh = open('test.mp4', 'r') +fh = open('test.mp4') frame_count = 0 diff --git a/scratchpad/decode.py b/scratchpad/decode.py index edfb413b7..96e5a202a 100644 --- a/scratchpad/decode.py +++ b/scratchpad/decode.py @@ -16,7 +16,7 @@ def format_time(time, time_base): if time is None: return 'None' - return '%.3fs (%s or %s/%s)' % (time_base * time, time_base * time, time_base.numerator * time, time_base.denominator) + return '{:.3f}s ({} or {}/{})'.format(time_base * time, time_base * time, time_base.numerator * time, time_base.denominator) arg_parser = argparse.ArgumentParser() @@ -45,7 +45,7 @@ def format_time(time, time_base): print('\tduration:', float(container.duration) / time_base) print('\tmetadata:') for k, v in sorted(container.metadata.items()): - print('\t\t%s: %r' % (k, v)) + print('\t\t{}: {!r}'.format(k, v)) print() print(len(container.streams), 'stream(s):') @@ -79,7 +79,7 @@ def format_time(time, time_base): print('\t\tmetadata:') for k, v in sorted(stream.metadata.items()): - print('\t\t\t%s: %r' % (k, v)) + print('\t\t\t{}: {!r}'.format(k, v)) print() @@ -145,7 +145,7 @@ def format_time(time, time_base): proc = subprocess.Popen(cmd, stdin=subprocess.PIPE) try: proc.stdin.write(bytes(frame.planes[0])) - except IOError as e: + except OSError as e: print(e) exit() diff --git a/scratchpad/filter_audio.py b/scratchpad/filter_audio.py index 092aba3ae..5483e62a5 100644 --- a/scratchpad/filter_audio.py +++ b/scratchpad/filter_audio.py @@ -34,7 +34,7 @@ def init_filter_graph(): OUTPUT_SAMPLE_RATE, OUTPUT_CHANNEL_LAYOUT ) - print('Output format: {}'.format(output_format)) + print(f'Output format: {output_format}') # initialize filters filter_chain = [ @@ -52,7 +52,7 @@ def init_filter_graph(): # link up the filters into a chain print('Filter graph:') for c, n in zip(filter_chain, filter_chain[1:]): - print('\t{} -> {}'.format(c, n)) + print(f'\t{c} -> {n}') c.link_to(n) # initialize the filter graph @@ -86,7 +86,7 @@ def process_output(frame): data = frame.to_ndarray() for i in range(data.shape[0]): m = hashlib.md5(data[i, :].tobytes()) - print('Plane: {:0d} checksum: {}'.format(i, m.hexdigest())) + print(f'Plane: {i:0d} checksum: {m.hexdigest()}') def main(duration): diff --git a/scratchpad/frame_seek_example.py b/scratchpad/frame_seek_example.py index 25b2d27d0..1f52d456b 100644 --- a/scratchpad/frame_seek_example.py +++ b/scratchpad/frame_seek_example.py @@ -41,7 +41,7 @@ class FrameGrabber(QtCore.QObject): update_frame_range = QtCore.pyqtSignal(object) def __init__(self, parent=None): - super(FrameGrabber, self).__init__(parent) + super().__init__(parent) self.file = None self.stream = None self.frame = None @@ -263,7 +263,7 @@ def set_file(self, path): class DisplayWidget(QtGui.QLabel): def __init__(self, parent=None): - super(DisplayWidget, self).__init__(parent) + super().__init__(parent) #self.setScaledContents(True) self.setMinimumSize(1920 / 10, 1080 / 10) @@ -286,7 +286,7 @@ def setPixmap(self, img, index): self.pixmap = QtGui.QPixmap.fromImage(img) #super(DisplayWidget, self).setPixmap(self.pixmap) - super(DisplayWidget, self).setPixmap(self.pixmap.scaled(self.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)) + super().setPixmap(self.pixmap.scaled(self.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)) def sizeHint(self): width = self.width() @@ -294,7 +294,7 @@ def sizeHint(self): def resizeEvent(self, event): if self.pixmap: - super(DisplayWidget, self).setPixmap(self.pixmap.scaled(self.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)) + super().setPixmap(self.pixmap.scaled(self.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)) def sizeHint(self): return QtCore.QSize(1920 / 2.5, 1080 / 2.5) @@ -307,7 +307,7 @@ class VideoPlayerWidget(QtGui.QWidget): load_file = QtCore.pyqtSignal(object) def __init__(self, parent=None): - super(VideoPlayerWidget, self).__init__(parent) + super().__init__(parent) self.display = DisplayWidget() self.timeline = QtGui.QScrollBar(Qt.Horizontal) self.frame_grabber = FrameGrabber() @@ -378,7 +378,7 @@ def keyPressEvent(self, event): self.timeline.setValue(self.timeline.value() + direction) else: - super(VideoPlayerWidget, self).keyPressEvent(event) + super().keyPressEvent(event) def mousePressEvent(self, event): # clear focus of spinbox @@ -386,7 +386,7 @@ def mousePressEvent(self, event): if focused_widget: focused_widget.clearFocus() - super(VideoPlayerWidget, self).mousePressEvent(event) + super().mousePressEvent(event) def dragEnterEvent(self, event): event.accept() diff --git a/scratchpad/glproxy.py b/scratchpad/glproxy.py index b6054e648..181ff1bac 100644 --- a/scratchpad/glproxy.py +++ b/scratchpad/glproxy.py @@ -14,7 +14,7 @@ '''.strip().split() -class ModuleProxy(object): +class ModuleProxy: def __init__(self, name, module): self.name = name diff --git a/scratchpad/qtproxy.py b/scratchpad/qtproxy.py index a39b76fa2..221c78302 100644 --- a/scratchpad/qtproxy.py +++ b/scratchpad/qtproxy.py @@ -4,7 +4,7 @@ from PyQt4 import QtCore, QtGui, QtOpenGL, QtMultimedia -class QtProxy(object): +class QtProxy: def __init__(self, *modules): self._modules = modules diff --git a/scratchpad/resource_use.py b/scratchpad/resource_use.py index 3387b0d70..930f808f5 100644 --- a/scratchpad/resource_use.py +++ b/scratchpad/resource_use.py @@ -58,4 +58,4 @@ def format_bytes(n): for i in range(len(usage) - 1): before = usage[i] after = usage[i + 1] - print('%s (%s)' % (format_bytes(after.ru_maxrss), format_bytes(after.ru_maxrss - before.ru_maxrss))) + print('{} ({})'.format(format_bytes(after.ru_maxrss), format_bytes(after.ru_maxrss - before.ru_maxrss))) diff --git a/scratchpad/second_seek_example.py b/scratchpad/second_seek_example.py index 58b3c3811..4b184c56b 100644 --- a/scratchpad/second_seek_example.py +++ b/scratchpad/second_seek_example.py @@ -41,7 +41,7 @@ class FrameGrabber(QtCore.QObject): update_frame_range = QtCore.pyqtSignal(object, object) def __init__(self, parent=None): - super(FrameGrabber, self).__init__(parent) + super().__init__(parent) self.file = None self.stream = None self.frame = None @@ -325,7 +325,7 @@ def set_file(self, path): class DisplayWidget(QtGui.QLabel): def __init__(self, parent=None): - super(DisplayWidget, self).__init__(parent) + super().__init__(parent) #self.setScaledContents(True) self.setMinimumSize(1920 / 10, 1080 / 10) @@ -348,7 +348,7 @@ def setPixmap(self, img, index): self.pixmap = QtGui.QPixmap.fromImage(img) #super(DisplayWidget, self).setPixmap(self.pixmap) - super(DisplayWidget, self).setPixmap(self.pixmap.scaled(self.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)) + super().setPixmap(self.pixmap.scaled(self.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)) def sizeHint(self): width = self.width() @@ -356,7 +356,7 @@ def sizeHint(self): def resizeEvent(self, event): if self.pixmap: - super(DisplayWidget, self).setPixmap(self.pixmap.scaled(self.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)) + super().setPixmap(self.pixmap.scaled(self.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)) def sizeHint(self): return QtCore.QSize(1920 / 2.5, 1080 / 2.5) @@ -369,7 +369,7 @@ class VideoPlayerWidget(QtGui.QWidget): load_file = QtCore.pyqtSignal(object) def __init__(self, parent=None): - super(VideoPlayerWidget, self).__init__(parent) + super().__init__(parent) self.rate = None @@ -456,7 +456,7 @@ def keyPressEvent(self, event): self.frame_changed(self.frame_control.value() + direction) else: - super(VideoPlayerWidget, self).keyPressEvent(event) + super().keyPressEvent(event) def mousePressEvent(self, event): # clear focus of spinbox @@ -464,7 +464,7 @@ def mousePressEvent(self, event): if focused_widget: focused_widget.clearFocus() - super(VideoPlayerWidget, self).mousePressEvent(event) + super().mousePressEvent(event) def dragEnterEvent(self, event): event.accept() diff --git a/scratchpad/seekmany.py b/scratchpad/seekmany.py index 0b37e5118..a12b88a14 100644 --- a/scratchpad/seekmany.py +++ b/scratchpad/seekmany.py @@ -24,8 +24,7 @@ def iter_frames(): for packet in container.demux(stream): - for frame in packet.decode(): - yield frame + yield from packet.decode() for i in range(steps): diff --git a/scripts/fetch-vendor.py b/scripts/fetch-vendor.py index 3ea3a0c6d..60259ee54 100644 --- a/scripts/fetch-vendor.py +++ b/scripts/fetch-vendor.py @@ -36,7 +36,7 @@ def get_platform(): logging.basicConfig(level=logging.INFO) # read config file -with open(args.config_file, "r") as fp: +with open(args.config_file) as fp: config = json.load(fp) # create fresh destination directory diff --git a/tests/common.py b/tests/common.py index a49b7bec2..ea3748f2b 100644 --- a/tests/common.py +++ b/tests/common.py @@ -86,7 +86,7 @@ def _inner(self, *args, **kwargs): return _inner -class MethodLogger(object): +class MethodLogger: def __init__(self, obj): self._obj = obj self._log = [] @@ -142,7 +142,7 @@ def assertNdarraysEqual(self, a, b): msg = "" for equal in it: if not equal: - msg += "- arrays differ at index %s; %s %s\n" % ( + msg += "- arrays differ at index {}; {} {}\n".format( it.multi_index, a[it.multi_index], b[it.multi_index], @@ -173,7 +173,7 @@ def assertIs(self, a, b, msg=None): def assertIsNot(self, a, b, msg=None): if a is b: - self.fail(msg or "both are %r at 0x%x; %r" % (type(a), id(a), a)) + self.fail(msg or "both are {!r} at 0x{:x}; {!r}".format(type(a), id(a), a)) def assertIsNone(self, x, msg=None): if x is not None: @@ -185,16 +185,16 @@ def assertIsNotNone(self, x, msg=None): def assertIn(self, a, b, msg=None): if a not in b: - self.fail(msg or "%r not in %r" % (a, b)) + self.fail(msg or "{!r} not in {!r}".format(a, b)) def assertNotIn(self, a, b, msg=None): if a in b: - self.fail(msg or "%r in %r" % (a, b)) + self.fail(msg or "{!r} in {!r}".format(a, b)) def assertIsInstance(self, instance, types, msg=None): if not isinstance(instance, types): - self.fail(msg or "not an instance of %r; %r" % (types, instance)) + self.fail(msg or "not an instance of {!r}; {!r}".format(types, instance)) def assertNotIsInstance(self, instance, types, msg=None): if isinstance(instance, types): - self.fail(msg or "is an instance of %r; %r" % (types, instance)) + self.fail(msg or "is an instance of {!r}; {!r}".format(types, instance)) diff --git a/tests/test_codec_context.py b/tests/test_codec_context.py index c94945a54..7a8e4a19b 100644 --- a/tests/test_codec_context.py +++ b/tests/test_codec_context.py @@ -13,8 +13,7 @@ def iter_frames(container, stream): for packet in container.demux(stream): - for frame in packet.decode(): - yield frame + yield from packet.decode() def iter_raw_frames(path, packet_sizes, ctx): @@ -26,15 +25,13 @@ def iter_raw_frames(path, packet_sizes, ctx): assert read_size == size if not read_size: break - for frame in ctx.decode(packet): - yield frame + yield from ctx.decode(packet) while True: try: frames = ctx.decode(None) except EOFError: break - for frame in frames: - yield frame + yield from frames if not frames: break diff --git a/tests/test_deprecation.py b/tests/test_deprecation.py index abdc79f8e..166104c42 100644 --- a/tests/test_deprecation.py +++ b/tests/test_deprecation.py @@ -7,7 +7,7 @@ class TestDeprecations(TestCase): def test_method(self): - class Example(object): + class Example: def __init__(self, x=100): self.x = x @@ -22,7 +22,7 @@ def foo(self, a, b): self.assertIn("Example.foo is deprecated", captured[0].message.args[0]) def test_renamed_attr(self): - class Example(object): + class Example: new_value = "foo" old_value = deprecation.renamed_attr("new_value") diff --git a/tests/test_enums.py b/tests/test_enums.py index c22e659fb..6219785d7 100644 --- a/tests/test_enums.py +++ b/tests/test_enums.py @@ -216,7 +216,7 @@ def test_properties(self): Flags = self.define_foobar(is_flags=True) foobar = Flags.FOO | Flags.BAR - class Class(object): + class Class: def __init__(self, value): self.value = Flags[value].value diff --git a/tests/test_errors.py b/tests/test_errors.py index 55d969999..56069515e 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -12,7 +12,7 @@ def test_stringify(self): for cls in (av.ValueError, av.FileNotFoundError, av.DecoderNotFoundError): e = cls(1, "foo") self.assertEqual(str(e), "[Errno 1] foo") - self.assertEqual(repr(e), "{}(1, 'foo')".format(cls.__name__)) + self.assertEqual(repr(e), f"{cls.__name__}(1, 'foo')") self.assertEqual( traceback.format_exception_only(cls, e)[-1], "{}{}: [Errno 1] foo\n".format( @@ -24,7 +24,7 @@ def test_stringify(self): for cls in (av.ValueError, av.FileNotFoundError, av.DecoderNotFoundError): e = cls(1, "foo", "bar.txt") self.assertEqual(str(e), "[Errno 1] foo: 'bar.txt'") - self.assertEqual(repr(e), "{}(1, 'foo', 'bar.txt')".format(cls.__name__)) + self.assertEqual(repr(e), f"{cls.__name__}(1, 'foo', 'bar.txt')") self.assertEqual( traceback.format_exception_only(cls, e)[-1], "{}{}: [Errno 1] foo: 'bar.txt'\n".format( diff --git a/tests/test_python_io.py b/tests/test_python_io.py index 8c341ab2d..8d372a84a 100644 --- a/tests/test_python_io.py +++ b/tests/test_python_io.py @@ -72,7 +72,7 @@ def seekable(self): CUSTOM_IO_PROTOCOL = "pyavtest://" -class CustomIOLogger(object): +class CustomIOLogger: """Log calls to open a file as well as method calls on the files""" def __init__(self): @@ -96,7 +96,7 @@ def io_open(self, url, flags, options): elif (flags & 2) == 2: mode = "wb" else: - raise RuntimeError("Unsupported io open mode {}".format(flags)) + raise RuntimeError(f"Unsupported io open mode {flags}") return MethodLogger(open(url, mode))