From fcb87ff21926a56528ca18ae0aab80afc3950e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeremy=20Lain=C3=A9?= Date: Mon, 30 Oct 2023 16:36:34 +0100 Subject: [PATCH 1/3] Remove inheritance from `object` class, it's not needed --- av/audio/format.pxd | 2 +- av/audio/format.pyx | 2 +- av/audio/layout.pxd | 4 ++-- av/audio/layout.pyx | 4 ++-- av/audio/resampler.pxd | 2 +- av/audio/resampler.pyx | 2 +- av/buffer.pxd | 2 +- av/buffer.pyx | 2 +- av/bytesource.pxd | 2 +- av/bytesource.pyx | 2 +- av/codec/codec.pxd | 2 +- av/codec/codec.pyx | 2 +- av/codec/context.pxd | 2 +- av/codec/context.pyx | 2 +- av/container/core.pxd | 2 +- av/container/core.pyx | 2 +- av/container/pyio.pxd | 2 +- av/container/pyio.pyx | 2 +- av/container/streams.pxd | 2 +- av/container/streams.pyx | 2 +- av/deprecation.py | 4 ++-- av/descriptor.pxd | 2 +- av/descriptor.pyx | 2 +- av/dictionary.pxd | 2 +- av/dictionary.pyx | 2 +- av/enum.pyx | 4 ++-- av/filter/context.pxd | 2 +- av/filter/context.pyx | 2 +- av/filter/filter.pxd | 2 +- av/filter/filter.pyx | 2 +- av/filter/graph.pxd | 2 +- av/filter/graph.pyx | 2 +- av/filter/link.pxd | 2 +- av/filter/link.pyx | 2 +- av/filter/pad.pxd | 2 +- av/filter/pad.pyx | 2 +- av/format.pxd | 2 +- av/format.pyx | 2 +- av/frame.pxd | 2 +- av/frame.pyx | 2 +- av/logging.pyx | 2 +- av/option.pxd | 2 +- av/option.pyx | 2 +- av/sidedata/motionvectors.pxd | 2 +- av/sidedata/motionvectors.pyx | 2 +- av/sidedata/sidedata.pxd | 2 +- av/sidedata/sidedata.pyx | 2 +- av/stream.pxd | 2 +- av/stream.pyx | 2 +- av/subtitles/subtitle.pxd | 8 ++++---- av/subtitles/subtitle.pyx | 8 ++++---- av/video/format.pxd | 4 ++-- av/video/format.pyx | 4 ++-- av/video/reformatter.pxd | 2 +- av/video/reformatter.pyx | 2 +- tests/common.py | 2 +- tests/test_deprecation.py | 4 ++-- tests/test_enums.py | 2 +- tests/test_python_io.py | 2 +- 59 files changed, 72 insertions(+), 72 deletions(-) diff --git a/av/audio/format.pxd b/av/audio/format.pxd index 5090f6886..4160aa85b 100644 --- a/av/audio/format.pxd +++ b/av/audio/format.pxd @@ -1,7 +1,7 @@ cimport libav as lib -cdef class AudioFormat(object): +cdef class AudioFormat: cdef lib.AVSampleFormat sample_fmt diff --git a/av/audio/format.pyx b/av/audio/format.pyx index f2eb72b5b..4c7cd1cdc 100644 --- a/av/audio/format.pyx +++ b/av/audio/format.pyx @@ -17,7 +17,7 @@ cdef AudioFormat get_audio_format(lib.AVSampleFormat c_format): return format -cdef class AudioFormat(object): +cdef class AudioFormat: """Descriptor of audio formats.""" diff --git a/av/audio/layout.pxd b/av/audio/layout.pxd index 60c8c953d..c46b9c741 100644 --- a/av/audio/layout.pxd +++ b/av/audio/layout.pxd @@ -1,7 +1,7 @@ from libc.stdint cimport uint64_t -cdef class AudioLayout(object): +cdef class AudioLayout: # The layout for FFMpeg; this is essentially a bitmask of channels. cdef uint64_t layout @@ -17,7 +17,7 @@ cdef class AudioLayout(object): cdef _init(self, uint64_t layout) -cdef class AudioChannel(object): +cdef class AudioChannel: # The channel for FFmpeg. cdef uint64_t channel diff --git a/av/audio/layout.pyx b/av/audio/layout.pyx index d4871553b..84801f47f 100644 --- a/av/audio/layout.pyx +++ b/av/audio/layout.pyx @@ -64,7 +64,7 @@ cdef dict channel_descriptions = { } -cdef class AudioLayout(object): +cdef class AudioLayout: def __init__(self, layout): @@ -105,7 +105,7 @@ cdef class AudioLayout(object): return out -cdef class AudioChannel(object): +cdef class AudioChannel: def __cinit__(self, AudioLayout layout, int index): self.channel = lib.av_channel_layout_extract_channel(layout.layout, index) diff --git a/av/audio/resampler.pxd b/av/audio/resampler.pxd index 4fe78b54a..d3601403d 100644 --- a/av/audio/resampler.pxd +++ b/av/audio/resampler.pxd @@ -4,7 +4,7 @@ from av.audio.layout cimport AudioLayout from av.filter.graph cimport Graph -cdef class AudioResampler(object): +cdef class AudioResampler: cdef readonly bint is_passthrough diff --git a/av/audio/resampler.pyx b/av/audio/resampler.pyx index b1c6c0aad..1214da317 100644 --- a/av/audio/resampler.pyx +++ b/av/audio/resampler.pyx @@ -7,7 +7,7 @@ import errno import av.filter -cdef class AudioResampler(object): +cdef class AudioResampler: """AudioResampler(format=None, layout=None, rate=None) diff --git a/av/buffer.pxd b/av/buffer.pxd index 199d2cc8b..cfab07ca0 100644 --- a/av/buffer.pxd +++ b/av/buffer.pxd @@ -1,5 +1,5 @@ -cdef class Buffer(object): +cdef class Buffer: cdef size_t _buffer_size(self) cdef void* _buffer_ptr(self) diff --git a/av/buffer.pyx b/av/buffer.pyx index 8176e1565..5affc81f0 100644 --- a/av/buffer.pyx +++ b/av/buffer.pyx @@ -5,7 +5,7 @@ from av import deprecation from av.bytesource cimport ByteSource, bytesource -cdef class Buffer(object): +cdef class Buffer: """A base class for PyAV objects which support the buffer protocol, such as :class:`.Packet` and :class:`.Plane`. diff --git a/av/bytesource.pxd b/av/bytesource.pxd index 68a6cca0f..050baab35 100644 --- a/av/bytesource.pxd +++ b/av/bytesource.pxd @@ -1,7 +1,7 @@ from cpython.buffer cimport Py_buffer -cdef class ByteSource(object): +cdef class ByteSource: cdef object owner diff --git a/av/bytesource.pyx b/av/bytesource.pyx index fd29bcf06..ec4138e72 100644 --- a/av/bytesource.pyx +++ b/av/bytesource.pyx @@ -6,7 +6,7 @@ from cpython.buffer cimport ( ) -cdef class ByteSource(object): +cdef class ByteSource: def __cinit__(self, owner): self.owner = owner diff --git a/av/codec/codec.pxd b/av/codec/codec.pxd index 173f0ef18..b9925df13 100644 --- a/av/codec/codec.pxd +++ b/av/codec/codec.pxd @@ -1,7 +1,7 @@ cimport libav as lib -cdef class Codec(object): +cdef class Codec: cdef const lib.AVCodec *ptr cdef const lib.AVCodecDescriptor *desc diff --git a/av/codec/codec.pyx b/av/codec/codec.pyx index 978d42775..46fafee15 100644 --- a/av/codec/codec.pyx +++ b/av/codec/codec.pyx @@ -138,7 +138,7 @@ class UnknownCodecError(ValueError): pass -cdef class Codec(object): +cdef class Codec: """Codec(name, mode='r') diff --git a/av/codec/context.pxd b/av/codec/context.pxd index 387cb7de4..6cc8bd899 100644 --- a/av/codec/context.pxd +++ b/av/codec/context.pxd @@ -7,7 +7,7 @@ from av.frame cimport Frame from av.packet cimport Packet -cdef class CodecContext(object): +cdef class CodecContext: cdef lib.AVCodecContext *ptr diff --git a/av/codec/context.pyx b/av/codec/context.pyx index 2cdf7ef5d..98b017f66 100644 --- a/av/codec/context.pyx +++ b/av/codec/context.pyx @@ -135,7 +135,7 @@ Flags2 = define_enum('Flags2', __name__, ( ), is_flags=True) -cdef class CodecContext(object): +cdef class CodecContext: @staticmethod def create(codec, mode=None): diff --git a/av/container/core.pxd b/av/container/core.pxd index 198c96fa8..fb7c3b511 100644 --- a/av/container/core.pxd +++ b/av/container/core.pxd @@ -13,7 +13,7 @@ ctypedef struct timeout_info: double timeout -cdef class Container(object): +cdef class Container: cdef readonly bint writeable cdef lib.AVFormatContext *ptr diff --git a/av/container/core.pyx b/av/container/core.pyx index 19675d5e0..aae294c17 100755 --- a/av/container/core.pyx +++ b/av/container/core.pyx @@ -166,7 +166,7 @@ Flags = define_enum('Flags', __name__, ( ), is_flags=True) -cdef class Container(object): +cdef class Container: def __cinit__(self, sentinel, file_, format_name, options, container_options, stream_options, diff --git a/av/container/pyio.pxd b/av/container/pyio.pxd index 0faeea4f1..e93a11dc8 100644 --- a/av/container/pyio.pxd +++ b/av/container/pyio.pxd @@ -13,7 +13,7 @@ cdef void pyio_close_gil(lib.AVIOContext *pb) cdef void pyio_close_custom_gil(lib.AVIOContext *pb) -cdef class PyIOFile(object): +cdef class PyIOFile: # File-like source. cdef readonly object file diff --git a/av/container/pyio.pyx b/av/container/pyio.pyx index 07224cd91..ed79b44f8 100644 --- a/av/container/pyio.pyx +++ b/av/container/pyio.pyx @@ -7,7 +7,7 @@ from av.error cimport stash_exception ctypedef int64_t (*seek_func_t)(void *opaque, int64_t offset, int whence) noexcept nogil -cdef class PyIOFile(object): +cdef class PyIOFile: def __cinit__(self, file, buffer_size, writeable=None): diff --git a/av/container/streams.pxd b/av/container/streams.pxd index 2ae69d84b..bf217d7c6 100644 --- a/av/container/streams.pxd +++ b/av/container/streams.pxd @@ -1,7 +1,7 @@ from av.stream cimport Stream -cdef class StreamContainer(object): +cdef class StreamContainer: cdef list _streams diff --git a/av/container/streams.pyx b/av/container/streams.pyx index eb85d9ff3..8de28a13e 100644 --- a/av/container/streams.pyx +++ b/av/container/streams.pyx @@ -11,7 +11,7 @@ def _flatten(input_): yield x -cdef class StreamContainer(object): +cdef class StreamContainer: """ diff --git a/av/deprecation.py b/av/deprecation.py index 1e0cbb317..f36d2fe6f 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,7 +68,7 @@ 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 diff --git a/av/descriptor.pxd b/av/descriptor.pxd index 98b039c5d..404f646af 100644 --- a/av/descriptor.pxd +++ b/av/descriptor.pxd @@ -1,7 +1,7 @@ cimport libav as lib -cdef class Descriptor(object): +cdef class Descriptor: # These are present as: # - AVCodecContext.av_class (same as avcodec_get_class()) diff --git a/av/descriptor.pyx b/av/descriptor.pyx index d945b0ac6..8debfa35e 100644 --- a/av/descriptor.pyx +++ b/av/descriptor.pyx @@ -13,7 +13,7 @@ cdef Descriptor wrap_avclass(const lib.AVClass *ptr): return obj -cdef class Descriptor(object): +cdef class Descriptor: def __cinit__(self, sentinel): if sentinel is not _cinit_sentinel: diff --git a/av/dictionary.pxd b/av/dictionary.pxd index 84cb24068..1c59df448 100644 --- a/av/dictionary.pxd +++ b/av/dictionary.pxd @@ -1,7 +1,7 @@ cimport libav as lib -cdef class _Dictionary(object): +cdef class _Dictionary: cdef lib.AVDictionary *ptr diff --git a/av/dictionary.pyx b/av/dictionary.pyx index d88ccebcd..3ebc09b89 100644 --- a/av/dictionary.pyx +++ b/av/dictionary.pyx @@ -3,7 +3,7 @@ from collections.abc import MutableMapping from av.error cimport err_check -cdef class _Dictionary(object): +cdef class _Dictionary: def __cinit__(self, *args, **kwargs): for arg in args: diff --git a/av/enum.pyx b/av/enum.pyx index 85f1b0748..19a5b6d46 100644 --- a/av/enum.pyx +++ b/av/enum.pyx @@ -135,7 +135,7 @@ def _unpickle(mod_name, cls_name, item_name): copyreg.constructor(_unpickle) -cdef class EnumItem(object): +cdef class EnumItem: """ Enumerations are when an attribute may only take on a single value at once, and @@ -322,7 +322,7 @@ cdef class EnumFlag(EnumItem): return bool(self.value) -cdef class EnumProperty(object): +cdef class EnumProperty: cdef object enum cdef object fget diff --git a/av/filter/context.pxd b/av/filter/context.pxd index 3c69185b2..18954fbdd 100644 --- a/av/filter/context.pxd +++ b/av/filter/context.pxd @@ -4,7 +4,7 @@ from av.filter.filter cimport Filter from av.filter.graph cimport Graph -cdef class FilterContext(object): +cdef class FilterContext: cdef lib.AVFilterContext *ptr cdef readonly Graph graph diff --git a/av/filter/context.pyx b/av/filter/context.pyx index 4b7eaed08..c97718f32 100644 --- a/av/filter/context.pyx +++ b/av/filter/context.pyx @@ -21,7 +21,7 @@ cdef FilterContext wrap_filter_context(Graph graph, Filter filter, lib.AVFilterC return self -cdef class FilterContext(object): +cdef class FilterContext: def __cinit__(self, sentinel): if sentinel is not _cinit_sentinel: diff --git a/av/filter/filter.pxd b/av/filter/filter.pxd index e3d937e7c..27501ae57 100644 --- a/av/filter/filter.pxd +++ b/av/filter/filter.pxd @@ -3,7 +3,7 @@ cimport libav as lib from av.descriptor cimport Descriptor -cdef class Filter(object): +cdef class Filter: cdef const lib.AVFilter *ptr diff --git a/av/filter/filter.pyx b/av/filter/filter.pyx index f5b5f1eee..57090a47d 100644 --- a/av/filter/filter.pyx +++ b/av/filter/filter.pyx @@ -21,7 +21,7 @@ cpdef enum FilterFlags: SUPPORT_TIMELINE_INTERNAL = lib.AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL -cdef class Filter(object): +cdef class Filter: def __cinit__(self, name): if name is _cinit_sentinel: diff --git a/av/filter/graph.pxd b/av/filter/graph.pxd index e01536527..c9226749c 100644 --- a/av/filter/graph.pxd +++ b/av/filter/graph.pxd @@ -3,7 +3,7 @@ cimport libav as lib from av.filter.context cimport FilterContext -cdef class Graph(object): +cdef class Graph: cdef lib.AVFilterGraph *ptr diff --git a/av/filter/graph.pyx b/av/filter/graph.pyx index bcb49f788..bf71fac9e 100644 --- a/av/filter/graph.pyx +++ b/av/filter/graph.pyx @@ -11,7 +11,7 @@ from av.video.format cimport VideoFormat from av.video.frame cimport VideoFrame -cdef class Graph(object): +cdef class Graph: def __cinit__(self): diff --git a/av/filter/link.pxd b/av/filter/link.pxd index 699838c38..a6a4b1c09 100644 --- a/av/filter/link.pxd +++ b/av/filter/link.pxd @@ -4,7 +4,7 @@ from av.filter.graph cimport Graph from av.filter.pad cimport FilterContextPad -cdef class FilterLink(object): +cdef class FilterLink: cdef readonly Graph graph cdef lib.AVFilterLink *ptr diff --git a/av/filter/link.pyx b/av/filter/link.pyx index 62e6ff8bc..c99e27f3b 100644 --- a/av/filter/link.pyx +++ b/av/filter/link.pyx @@ -6,7 +6,7 @@ from av.filter.graph cimport Graph cdef _cinit_sentinel = object() -cdef class FilterLink(object): +cdef class FilterLink: def __cinit__(self, sentinel): if sentinel is not _cinit_sentinel: diff --git a/av/filter/pad.pxd b/av/filter/pad.pxd index 088c0b0c0..15ac950fc 100644 --- a/av/filter/pad.pxd +++ b/av/filter/pad.pxd @@ -5,7 +5,7 @@ from av.filter.filter cimport Filter from av.filter.link cimport FilterLink -cdef class FilterPad(object): +cdef class FilterPad: cdef readonly Filter filter cdef readonly FilterContext context diff --git a/av/filter/pad.pyx b/av/filter/pad.pyx index 64ec9a6b1..482b2fc36 100644 --- a/av/filter/pad.pyx +++ b/av/filter/pad.pyx @@ -4,7 +4,7 @@ from av.filter.link cimport wrap_filter_link cdef object _cinit_sentinel = object() -cdef class FilterPad(object): +cdef class FilterPad: def __cinit__(self, sentinel): if sentinel is not _cinit_sentinel: diff --git a/av/format.pxd b/av/format.pxd index 8165daa4e..31cac50aa 100644 --- a/av/format.pxd +++ b/av/format.pxd @@ -1,7 +1,7 @@ cimport libav as lib -cdef class ContainerFormat(object): +cdef class ContainerFormat: cdef readonly str name diff --git a/av/format.pyx b/av/format.pyx index 05a5402a8..7afe4416f 100644 --- a/av/format.pyx +++ b/av/format.pyx @@ -59,7 +59,7 @@ Flags = define_enum('Flags', __name__, ( ), is_flags=True) -cdef class ContainerFormat(object): +cdef class ContainerFormat: """Descriptor of a container format. diff --git a/av/frame.pxd b/av/frame.pxd index e0d5b4280..34c302536 100644 --- a/av/frame.pxd +++ b/av/frame.pxd @@ -4,7 +4,7 @@ from av.packet cimport Packet from av.sidedata.sidedata cimport _SideDataContainer -cdef class Frame(object): +cdef class Frame: cdef lib.AVFrame *ptr diff --git a/av/frame.pyx b/av/frame.pyx index 3717ddc81..cab930334 100644 --- a/av/frame.pyx +++ b/av/frame.pyx @@ -5,7 +5,7 @@ from fractions import Fraction from av.sidedata.sidedata import SideDataContainer -cdef class Frame(object): +cdef class Frame: """ Base class for audio and video frames. diff --git a/av/logging.pyx b/av/logging.pyx index 2253560ad..4330da08a 100644 --- a/av/logging.pyx +++ b/av/logging.pyx @@ -168,7 +168,7 @@ cpdef get_last_error(): cdef global_captures = [] cdef thread_captures = {} -cdef class Capture(object): +cdef class Capture: """A context manager for capturing logs. diff --git a/av/option.pxd b/av/option.pxd index e455bff03..9087b811c 100644 --- a/av/option.pxd +++ b/av/option.pxd @@ -1,7 +1,7 @@ cimport libav as lib -cdef class BaseOption(object): +cdef class BaseOption: cdef const lib.AVOption *ptr diff --git a/av/option.pyx b/av/option.pyx index 24f945bf2..731a6d508 100644 --- a/av/option.pyx +++ b/av/option.pyx @@ -59,7 +59,7 @@ OptionFlags = define_enum('OptionFlags', __name__, ( ('FILTERING_PARAM', lib.AV_OPT_FLAG_FILTERING_PARAM), ), is_flags=True) -cdef class BaseOption(object): +cdef class BaseOption: def __cinit__(self, sentinel): if sentinel is not _cinit_sentinel: diff --git a/av/sidedata/motionvectors.pxd b/av/sidedata/motionvectors.pxd index 3b7f88bc1..993c5e283 100644 --- a/av/sidedata/motionvectors.pxd +++ b/av/sidedata/motionvectors.pxd @@ -10,7 +10,7 @@ cdef class _MotionVectors(SideData): cdef int _len -cdef class MotionVector(object): +cdef class MotionVector: cdef _MotionVectors parent cdef lib.AVMotionVector *ptr diff --git a/av/sidedata/motionvectors.pyx b/av/sidedata/motionvectors.pyx index 35d0e2f33..f1e12d56f 100644 --- a/av/sidedata/motionvectors.pyx +++ b/av/sidedata/motionvectors.pyx @@ -53,7 +53,7 @@ class MotionVectors(_MotionVectors, Sequence): pass -cdef class MotionVector(object): +cdef class MotionVector: def __init__(self, sentinel, _MotionVectors parent, int index): if sentinel is not _cinit_bypass_sentinel: diff --git a/av/sidedata/sidedata.pxd b/av/sidedata/sidedata.pxd index f30d8fef7..ac58f1477 100644 --- a/av/sidedata/sidedata.pxd +++ b/av/sidedata/sidedata.pxd @@ -15,7 +15,7 @@ cdef class SideData(Buffer): cdef SideData wrap_side_data(Frame frame, int index) -cdef class _SideDataContainer(object): +cdef class _SideDataContainer: cdef Frame frame diff --git a/av/sidedata/sidedata.pyx b/av/sidedata/sidedata.pyx index ec7de5997..17bb869cc 100644 --- a/av/sidedata/sidedata.pyx +++ b/av/sidedata/sidedata.pyx @@ -70,7 +70,7 @@ cdef class SideData(Buffer): return Type.get(self.ptr.type) or self.ptr.type -cdef class _SideDataContainer(object): +cdef class _SideDataContainer: def __init__(self, Frame frame): diff --git a/av/stream.pxd b/av/stream.pxd index 5ad3b965e..0edd9c83b 100644 --- a/av/stream.pxd +++ b/av/stream.pxd @@ -7,7 +7,7 @@ from av.frame cimport Frame from av.packet cimport Packet -cdef class Stream(object): +cdef class Stream: cdef lib.AVStream *ptr # Stream attributes. diff --git a/av/stream.pyx b/av/stream.pyx index 971eaded1..56127ccb2 100644 --- a/av/stream.pyx +++ b/av/stream.pyx @@ -53,7 +53,7 @@ cdef Stream wrap_stream(Container container, lib.AVStream *c_stream, CodecContex return py_stream -cdef class Stream(object): +cdef class Stream: """ A single stream of audio, video or subtitles within a :class:`.Container`. diff --git a/av/subtitles/subtitle.pxd b/av/subtitles/subtitle.pxd index ae7bb44b9..e9003ab9b 100644 --- a/av/subtitles/subtitle.pxd +++ b/av/subtitles/subtitle.pxd @@ -3,19 +3,19 @@ cimport libav as lib from av.packet cimport Packet -cdef class SubtitleProxy(object): +cdef class SubtitleProxy: cdef lib.AVSubtitle struct -cdef class SubtitleSet(object): +cdef class SubtitleSet: cdef readonly Packet packet cdef SubtitleProxy proxy cdef readonly tuple rects -cdef class Subtitle(object): +cdef class Subtitle: cdef SubtitleProxy proxy cdef lib.AVSubtitleRect *ptr @@ -31,7 +31,7 @@ cdef class BitmapSubtitle(Subtitle): cdef readonly planes -cdef class BitmapSubtitlePlane(object): +cdef class BitmapSubtitlePlane: cdef readonly BitmapSubtitle subtitle cdef readonly int index diff --git a/av/subtitles/subtitle.pyx b/av/subtitles/subtitle.pyx index 2f22bb0be..1f0e4319a 100644 --- a/av/subtitles/subtitle.pyx +++ b/av/subtitles/subtitle.pyx @@ -1,12 +1,12 @@ from cpython cimport PyBuffer_FillInfo -cdef class SubtitleProxy(object): +cdef class SubtitleProxy: def __dealloc__(self): lib.avsubtitle_free(&self.struct) -cdef class SubtitleSet(object): +cdef class SubtitleSet: def __cinit__(self, SubtitleProxy proxy): self.proxy = proxy @@ -63,7 +63,7 @@ cdef Subtitle build_subtitle(SubtitleSet subtitle, int index): raise ValueError('unknown subtitle type %r' % ptr.type) -cdef class Subtitle(object): +cdef class Subtitle: def __cinit__(self, SubtitleSet subtitle, int index): if index < 0 or index >= subtitle.proxy.struct.num_rects: @@ -131,7 +131,7 @@ cdef class BitmapSubtitle(Subtitle): return self.planes[i] -cdef class BitmapSubtitlePlane(object): +cdef class BitmapSubtitlePlane: def __cinit__(self, BitmapSubtitle subtitle, int index): diff --git a/av/video/format.pxd b/av/video/format.pxd index 923f05c44..a2efa9d1d 100644 --- a/av/video/format.pxd +++ b/av/video/format.pxd @@ -1,7 +1,7 @@ cimport libav as lib -cdef class VideoFormat(object): +cdef class VideoFormat: cdef lib.AVPixelFormat pix_fmt cdef const lib.AVPixFmtDescriptor *ptr @@ -15,7 +15,7 @@ cdef class VideoFormat(object): cpdef chroma_height(self, int luma_height=?) -cdef class VideoFormatComponent(object): +cdef class VideoFormatComponent: cdef VideoFormat format cdef readonly unsigned int index diff --git a/av/video/format.pyx b/av/video/format.pyx index b96658272..602ec5275 100644 --- a/av/video/format.pyx +++ b/av/video/format.pyx @@ -19,7 +19,7 @@ cdef lib.AVPixelFormat get_pix_fmt(const char *name) except lib.AV_PIX_FMT_NONE: return pix_fmt -cdef class VideoFormat(object): +cdef class VideoFormat: """ >>> format = VideoFormat('rgb24') @@ -118,7 +118,7 @@ cdef class VideoFormat(object): return -((-luma_height) >> self.ptr.log2_chroma_h) if luma_height else 0 -cdef class VideoFormatComponent(object): +cdef class VideoFormatComponent: def __cinit__(self, VideoFormat format, size_t index): self.format = format diff --git a/av/video/reformatter.pxd b/av/video/reformatter.pxd index 25135c27a..ee7467898 100644 --- a/av/video/reformatter.pxd +++ b/av/video/reformatter.pxd @@ -3,7 +3,7 @@ cimport libav as lib from av.video.frame cimport VideoFrame -cdef class VideoReformatter(object): +cdef class VideoReformatter: cdef lib.SwsContext *ptr diff --git a/av/video/reformatter.pyx b/av/video/reformatter.pyx index 3ad995fb9..1d3f08065 100644 --- a/av/video/reformatter.pyx +++ b/av/video/reformatter.pyx @@ -42,7 +42,7 @@ Colorspace = define_enum('Colorspace', __name__, ( )) -cdef class VideoReformatter(object): +cdef class VideoReformatter: """An object for reformatting size and pixel format of :class:`.VideoFrame`. diff --git a/tests/common.py b/tests/common.py index a49b7bec2..8431ba911 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 = [] diff --git a/tests/test_deprecation.py b/tests/test_deprecation.py index d728c330d..f8857ab73 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 d8b727dab..bc8385f5e 100644 --- a/tests/test_enums.py +++ b/tests/test_enums.py @@ -204,7 +204,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_python_io.py b/tests/test_python_io.py index 4e7d61f59..84e94d7a3 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): From d937ef83a807333e934bdfc94c845ddfccdf405c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeremy=20Lain=C3=A9?= Date: Mon, 30 Oct 2023 17:02:42 +0100 Subject: [PATCH 2/3] Prune some useless imports from Cython code --- av/audio/codeccontext.pyx | 1 - av/audio/fifo.pyx | 2 -- av/audio/frame.pyx | 1 - av/audio/plane.pyx | 2 -- av/codec/codec.pyx | 2 +- av/codec/context.pyx | 2 +- av/container/core.pyx | 5 ----- av/container/input.pyx | 2 +- av/container/output.pyx | 1 - av/enum.pyx | 2 -- av/filter/context.pyx | 6 ++---- av/frame.pyx | 2 -- av/logging.pyx | 2 +- av/stream.pxd | 1 - av/stream.pyx | 6 +----- av/subtitles/codeccontext.pyx | 1 - av/utils.pxd | 2 +- av/utils.pyx | 2 +- av/video/codeccontext.pyx | 1 - av/video/frame.pxd | 2 +- av/video/frame.pyx | 2 +- include/libavcodec/avcodec.pxd | 7 +------ include/libavutil/motion_vector.pxd | 7 +------ include/libswresample/swresample.pxd | 1 + 24 files changed, 14 insertions(+), 48 deletions(-) diff --git a/av/audio/codeccontext.pyx b/av/audio/codeccontext.pyx index c81a49dd8..8446fbcd0 100644 --- a/av/audio/codeccontext.pyx +++ b/av/audio/codeccontext.pyx @@ -3,7 +3,6 @@ cimport libav as lib from av.audio.format cimport AudioFormat, get_audio_format from av.audio.frame cimport AudioFrame, alloc_audio_frame from av.audio.layout cimport AudioLayout, get_audio_layout -from av.error cimport err_check from av.frame cimport Frame from av.packet cimport Packet diff --git a/av/audio/fifo.pyx b/av/audio/fifo.pyx index 6d1d17bd7..9b95d5770 100644 --- a/av/audio/fifo.pyx +++ b/av/audio/fifo.pyx @@ -1,6 +1,4 @@ -from av.audio.format cimport get_audio_format from av.audio.frame cimport alloc_audio_frame -from av.audio.layout cimport get_audio_layout from av.error cimport err_check diff --git a/av/audio/frame.pyx b/av/audio/frame.pyx index 97de3cc53..b97d5e043 100644 --- a/av/audio/frame.pyx +++ b/av/audio/frame.pyx @@ -56,7 +56,6 @@ cdef class AudioFrame(Frame): # Audio filters need AVFrame.channels to match number of channels from layout. self.ptr.channels = self.layout.nb_channels - cdef size_t buffer_size if self.layout.channels and nb_samples: # Cleanup the old buffer. diff --git a/av/audio/plane.pyx b/av/audio/plane.pyx index 50fe0aa59..92c508cbd 100644 --- a/av/audio/plane.pyx +++ b/av/audio/plane.pyx @@ -1,5 +1,3 @@ -cimport libav as lib - from av.audio.frame cimport AudioFrame diff --git a/av/codec/codec.pyx b/av/codec/codec.pyx index 46fafee15..a7002acc2 100644 --- a/av/codec/codec.pyx +++ b/av/codec/codec.pyx @@ -1,7 +1,7 @@ from av.audio.format cimport get_audio_format from av.descriptor cimport wrap_avclass from av.enum cimport define_enum -from av.utils cimport avrational_to_fraction, flag_in_bitfield +from av.utils cimport avrational_to_fraction from av.video.format cimport get_video_format diff --git a/av/codec/context.pyx b/av/codec/context.pyx index 98b017f66..bc8b35d57 100644 --- a/av/codec/context.pyx +++ b/av/codec/context.pyx @@ -1,7 +1,7 @@ import warnings from libc.errno cimport EAGAIN -from libc.stdint cimport int64_t, uint8_t +from libc.stdint cimport uint8_t from libc.string cimport memcpy cimport libav as lib diff --git a/av/container/core.pyx b/av/container/core.pyx index aae294c17..5b1711a53 100755 --- a/av/container/core.pyx +++ b/av/container/core.pyx @@ -1,6 +1,5 @@ from cython.operator cimport dereference from libc.stdint cimport int64_t -from libc.stdlib cimport free, malloc import os import time @@ -20,9 +19,6 @@ from av.dictionary import Dictionary from av.logging import Capture as LogCapture -ctypedef int64_t (*seek_func_t)(void *opaque, int64_t offset, int whence) noexcept nogil - - cdef object _cinit_sentinel = object() @@ -207,7 +203,6 @@ cdef class Container: cdef bytes name_obj = os.fsencode(self.name) cdef char *name = name_obj - cdef seek_func_t seek_func = NULL cdef lib.AVOutputFormat *ofmt if self.writeable: diff --git a/av/container/input.pyx b/av/container/input.pyx index e508f16f4..80cd8f783 100644 --- a/av/container/input.pyx +++ b/av/container/input.pyx @@ -79,7 +79,7 @@ cdef class InputContainer(Container): codec_context.pkt_timebase = stream.time_base py_codec_context = wrap_codec_context(codec_context, codec) else: - # no decoder is available + # no decoder is available py_codec_context = None self.streams.add_stream(wrap_stream(self, stream, py_codec_context)) diff --git a/av/container/output.pyx b/av/container/output.pyx index 0107ff17e..788b3214d 100644 --- a/av/container/output.pyx +++ b/av/container/output.pyx @@ -1,4 +1,3 @@ -from fractions import Fraction import logging import os diff --git a/av/enum.pyx b/av/enum.pyx index 19a5b6d46..522948bbb 100644 --- a/av/enum.pyx +++ b/av/enum.pyx @@ -9,9 +9,7 @@ integers for names and values respectively. """ -from collections import OrderedDict import copyreg -import sys cdef sentinel = object() diff --git a/av/filter/context.pyx b/av/filter/context.pyx index c97718f32..4505c7cd3 100644 --- a/av/filter/context.pyx +++ b/av/filter/context.pyx @@ -1,13 +1,11 @@ -from libc.string cimport memcpy - -from av.audio.frame cimport AudioFrame, alloc_audio_frame +from av.audio.frame cimport alloc_audio_frame from av.dictionary cimport _Dictionary from av.dictionary import Dictionary from av.error cimport err_check from av.filter.pad cimport alloc_filter_pads from av.frame cimport Frame from av.utils cimport avrational_to_fraction -from av.video.frame cimport VideoFrame, alloc_video_frame +from av.video.frame cimport alloc_video_frame cdef object _cinit_sentinel = object() diff --git a/av/frame.pyx b/av/frame.pyx index cab930334..b98624cc5 100644 --- a/av/frame.pyx +++ b/av/frame.pyx @@ -1,7 +1,5 @@ from av.utils cimport avrational_to_fraction, to_avrational -from fractions import Fraction - from av.sidedata.sidedata import SideDataContainer diff --git a/av/logging.pyx b/av/logging.pyx index 4330da08a..131b9a69f 100644 --- a/av/logging.pyx +++ b/av/logging.pyx @@ -32,7 +32,7 @@ API Reference from __future__ import absolute_import -from libc.stdio cimport fprintf, printf, stderr +from libc.stdio cimport fprintf, stderr from libc.stdlib cimport free, malloc cimport libav as lib diff --git a/av/stream.pxd b/av/stream.pxd index 0edd9c83b..c847f641e 100644 --- a/av/stream.pxd +++ b/av/stream.pxd @@ -1,4 +1,3 @@ -from libc.stdint cimport int64_t cimport libav as lib from av.codec.context cimport CodecContext diff --git a/av/stream.pyx b/av/stream.pyx index 56127ccb2..f9b6d7ec5 100644 --- a/av/stream.pyx +++ b/av/stream.pyx @@ -1,11 +1,7 @@ import warnings -from cpython cimport PyWeakref_NewRef -from libc.stdint cimport int64_t, uint8_t -from libc.string cimport memcpy cimport libav as lib -from av.codec.context cimport wrap_codec_context from av.error cimport err_check from av.packet cimport Packet from av.utils cimport ( @@ -100,7 +96,7 @@ cdef class Stream: def __getattr__(self, name): # Deprecate framerate pass-through as it is not always set. - # See: https://github.com/PyAV-Org/PyAV/issues/1005 + # See: https://github.com/PyAV-Org/PyAV/issues/1005 if self.ptr.codecpar.codec_type == lib.AVMEDIA_TYPE_VIDEO and name in ("framerate", "rate"): warnings.warn( "VideoStream.%s is deprecated as it is not always set; please use VideoStream.average_rate." % name, diff --git a/av/subtitles/codeccontext.pyx b/av/subtitles/codeccontext.pyx index a120fc3a5..c3f433abe 100644 --- a/av/subtitles/codeccontext.pyx +++ b/av/subtitles/codeccontext.pyx @@ -1,7 +1,6 @@ cimport libav as lib from av.error cimport err_check -from av.frame cimport Frame from av.packet cimport Packet from av.subtitles.subtitle cimport SubtitleProxy, SubtitleSet diff --git a/av/utils.pxd b/av/utils.pxd index 0c943de81..bc5d56927 100644 --- a/av/utils.pxd +++ b/av/utils.pxd @@ -1,4 +1,4 @@ -from libc.stdint cimport int64_t, uint8_t, uint64_t +from libc.stdint cimport uint64_t cimport libav as lib diff --git a/av/utils.pyx b/av/utils.pyx index 1894ce7ab..1b25a38fe 100644 --- a/av/utils.pyx +++ b/av/utils.pyx @@ -1,4 +1,4 @@ -from libc.stdint cimport int64_t, uint8_t, uint64_t +from libc.stdint cimport uint64_t from fractions import Fraction diff --git a/av/video/codeccontext.pyx b/av/video/codeccontext.pyx index 8dac3b3fe..33efc5d54 100644 --- a/av/video/codeccontext.pyx +++ b/av/video/codeccontext.pyx @@ -2,7 +2,6 @@ from libc.stdint cimport int64_t cimport libav as lib from av.codec.context cimport CodecContext -from av.error cimport err_check from av.frame cimport Frame from av.packet cimport Packet from av.utils cimport avrational_to_fraction, to_avrational diff --git a/av/video/frame.pxd b/av/video/frame.pxd index a08da1ecc..709775e55 100644 --- a/av/video/frame.pxd +++ b/av/video/frame.pxd @@ -1,4 +1,4 @@ -from libc.stdint cimport int16_t, int32_t, uint8_t, uint16_t, uint64_t +from libc.stdint cimport uint8_t cimport libav as lib from av.frame cimport Frame diff --git a/av/video/frame.pyx b/av/video/frame.pyx index 972abb779..971b88ccc 100644 --- a/av/video/frame.pyx +++ b/av/video/frame.pyx @@ -5,7 +5,7 @@ from libc.stdint cimport uint8_t from av.enum cimport define_enum from av.error cimport err_check from av.utils cimport check_ndarray, check_ndarray_shape -from av.video.format cimport VideoFormat, get_pix_fmt, get_video_format +from av.video.format cimport get_pix_fmt, get_video_format from av.video.plane cimport VideoPlane diff --git a/include/libavcodec/avcodec.pxd b/include/libavcodec/avcodec.pxd index 0334b18e4..11d968b1a 100644 --- a/include/libavcodec/avcodec.pxd +++ b/include/libavcodec/avcodec.pxd @@ -1,9 +1,4 @@ -from libc.stdint cimport ( - uint8_t, int8_t, - uint16_t, int16_t, - uint32_t, int32_t, - uint64_t, int64_t -) +from libc.stdint cimport int8_t, int64_t, uint16_t, uint32_t cdef extern from "libavcodec/avcodec.h" nogil: diff --git a/include/libavutil/motion_vector.pxd b/include/libavutil/motion_vector.pxd index bcf61c0d1..457d7149e 100644 --- a/include/libavutil/motion_vector.pxd +++ b/include/libavutil/motion_vector.pxd @@ -1,9 +1,4 @@ -from libc.stdint cimport ( - uint8_t, int8_t, - uint16_t, int16_t, - uint32_t, int32_t, - uint64_t, int64_t -) +from libc.stdint cimport int16_t, int32_t, uint8_t, uint16_t, uint64_t cdef extern from "libavutil/motion_vector.h" nogil: diff --git a/include/libswresample/swresample.pxd b/include/libswresample/swresample.pxd index 703310139..d76b777a3 100644 --- a/include/libswresample/swresample.pxd +++ b/include/libswresample/swresample.pxd @@ -1,5 +1,6 @@ from libc.stdint cimport int64_t, uint8_t + cdef extern from "libswresample/swresample.h" nogil: cdef int swresample_version() From 2a0cb22b55916b60223cae9e4a26cea8f7b27a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeremy=20Lain=C3=A9?= Date: Mon, 30 Oct 2023 17:28:13 +0100 Subject: [PATCH 3/3] Remove backports of `unittest` matchers This is unnecessary since we only support Python 3. --- tests/common.py | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/tests/common.py b/tests/common.py index 8431ba911..5b12ca0d9 100644 --- a/tests/common.py +++ b/tests/common.py @@ -3,7 +3,6 @@ import errno import functools import os -import sys import types from av.datasets import fate as fate_suite @@ -159,42 +158,3 @@ def assertImagesAlmostEqual(self, a, b, epsilon=0.1, *args): self.fail( "images differed by %s at index %d; %s %s" % (diff, i, ax, bx) ) - - # Add some of the unittest methods that we love from 2.7. - if sys.version_info < (2, 7): - - def assertIs(self, a, b, msg=None): - if a is not b: - self.fail( - msg - or "%r at 0x%x is not %r at 0x%x; %r is not %r" - % (type(a), id(a), type(b), id(b), a, b) - ) - - 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)) - - def assertIsNone(self, x, msg=None): - if x is not None: - self.fail(msg or "is not None; %r" % x) - - def assertIsNotNone(self, x, msg=None): - if x is None: - self.fail(msg or "is None; %r" % x) - - def assertIn(self, a, b, msg=None): - if a not in b: - self.fail(msg or "%r not in %r" % (a, b)) - - def assertNotIn(self, a, b, msg=None): - if a in b: - self.fail(msg or "%r in %r" % (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)) - - def assertNotIsInstance(self, instance, types, msg=None): - if isinstance(instance, types): - self.fail(msg or "is an instance of %r; %r" % (types, instance))