Skip to content

Commit 92a4750

Browse files
JoeSchiffWyattBlue
authored andcommitted
Convert deprecated cython extension class properties to new syntax part 2
1 parent 6bc9621 commit 92a4750

File tree

5 files changed

+125
-115
lines changed

5 files changed

+125
-115
lines changed

av/audio/codeccontext.pyx

+43-36
Original file line numberDiff line numberDiff line change
@@ -53,69 +53,76 @@ cdef class AudioCodecContext(CodecContext):
5353
cdef AudioFrame aframe = frame
5454
aframe._init_user_attributes()
5555

56-
property frame_size:
56+
@property
57+
def frame_size(self):
5758
"""
5859
Number of samples per channel in an audio frame.
5960
6061
:type: int
6162
"""
62-
def __get__(self): return self.ptr.frame_size
63+
return self.ptr.frame_size
6364

64-
property sample_rate:
65+
66+
@property
67+
def sample_rate(self):
6568
"""
6669
Sample rate of the audio data, in samples per second.
6770
6871
:type: int
6972
"""
70-
def __get__(self):
71-
return self.ptr.sample_rate
73+
return self.ptr.sample_rate
7274

73-
def __set__(self, int value):
74-
self.ptr.sample_rate = value
75+
@sample_rate.setter
76+
def sample_rate(self, int value):
77+
self.ptr.sample_rate = value
7578

76-
property rate:
79+
@property
80+
def rate(self):
7781
"""Another name for :attr:`sample_rate`."""
78-
def __get__(self):
79-
return self.sample_rate
82+
return self.sample_rate
8083

81-
def __set__(self, value):
82-
self.sample_rate = value
84+
@rate.setter
85+
def rate(self, value):
86+
self.sample_rate = value
8387

8488
# TODO: Integrate into AudioLayout.
85-
property channels:
86-
def __get__(self):
87-
return self.ptr.channels
88-
89-
def __set__(self, value):
90-
self.ptr.channels = value
91-
self.ptr.channel_layout = lib.av_get_default_channel_layout(value)
92-
property channel_layout:
93-
def __get__(self):
94-
return self.ptr.channel_layout
95-
96-
property layout:
89+
@property
90+
def channels(self):
91+
return self.ptr.channels
92+
93+
@channels.setter
94+
def channels(self, value):
95+
self.ptr.channels = value
96+
self.ptr.channel_layout = lib.av_get_default_channel_layout(value)
97+
@property
98+
def channel_layout(self):
99+
return self.ptr.channel_layout
100+
101+
@property
102+
def layout(self):
97103
"""
98104
The audio channel layout.
99105
100106
:type: AudioLayout
101107
"""
102-
def __get__(self):
103-
return get_audio_layout(self.ptr.channels, self.ptr.channel_layout)
108+
return get_audio_layout(self.ptr.channels, self.ptr.channel_layout)
104109

105-
def __set__(self, value):
106-
cdef AudioLayout layout = AudioLayout(value)
107-
self.ptr.channel_layout = layout.layout
108-
self.ptr.channels = layout.nb_channels
110+
@layout.setter
111+
def layout(self, value):
112+
cdef AudioLayout layout = AudioLayout(value)
113+
self.ptr.channel_layout = layout.layout
114+
self.ptr.channels = layout.nb_channels
109115

110-
property format:
116+
@property
117+
def format(self):
111118
"""
112119
The audio sample format.
113120
114121
:type: AudioFormat
115122
"""
116-
def __get__(self):
117-
return get_audio_format(self.ptr.sample_fmt)
123+
return get_audio_format(self.ptr.sample_fmt)
118124

119-
def __set__(self, value):
120-
cdef AudioFormat format = AudioFormat(value)
121-
self.ptr.sample_fmt = format.sample_fmt
125+
@format.setter
126+
def format(self, value):
127+
cdef AudioFormat format = AudioFormat(value)
128+
self.ptr.sample_fmt = format.sample_fmt

av/audio/fifo.pyx

+12-12
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,19 @@ cdef class AudioFifo:
173173

174174
return frames
175175

176-
property format:
176+
@property
177+
def format(self):
177178
"""The :class:`.AudioFormat` of this FIFO."""
178-
def __get__(self):
179-
return self.template.format
180-
property layout:
179+
return self.template.format
180+
@property
181+
def layout(self):
181182
"""The :class:`.AudioLayout` of this FIFO."""
182-
def __get__(self):
183-
return self.template.layout
184-
property sample_rate:
185-
def __get__(self):
186-
return self.template.sample_rate
183+
return self.template.layout
184+
@property
185+
def sample_rate(self):
186+
return self.template.sample_rate
187187

188-
property samples:
188+
@property
189+
def samples(self):
189190
"""Number of audio samples (per channel) in the buffer."""
190-
def __get__(self):
191-
return lib.av_audio_fifo_size(self.ptr) if self.ptr else 0
191+
return lib.av_audio_fifo_size(self.ptr) if self.ptr else 0

av/audio/format.pyx

+43-42
Original file line numberDiff line numberDiff line change
@@ -41,70 +41,72 @@ cdef class AudioFormat:
4141
def __repr__(self):
4242
return f"<av.AudioFormat {self.name}>"
4343

44-
property name:
44+
@property
45+
def name(self):
4546
"""Canonical name of the sample format.
4647
4748
>>> SampleFormat('s16p').name
4849
's16p'
4950
5051
"""
51-
def __get__(self):
52-
return <str>lib.av_get_sample_fmt_name(self.sample_fmt)
52+
return <str>lib.av_get_sample_fmt_name(self.sample_fmt)
5353

54-
property bytes:
54+
@property
55+
def bytes(self):
5556
"""Number of bytes per sample.
5657
5758
>>> SampleFormat('s16p').bytes
5859
2
5960
6061
"""
61-
def __get__(self):
62-
return lib.av_get_bytes_per_sample(self.sample_fmt)
62+
return lib.av_get_bytes_per_sample(self.sample_fmt)
6363

64-
property bits:
64+
@property
65+
def bits(self):
6566
"""Number of bits per sample.
6667
6768
>>> SampleFormat('s16p').bits
6869
16
6970
7071
"""
71-
def __get__(self):
72-
return lib.av_get_bytes_per_sample(self.sample_fmt) << 3
72+
return lib.av_get_bytes_per_sample(self.sample_fmt) << 3
7373

74-
property is_planar:
74+
@property
75+
def is_planar(self):
7576
"""Is this a planar format?
7677
7778
Strictly opposite of :attr:`is_packed`.
7879
7980
"""
80-
def __get__(self):
81-
return bool(lib.av_sample_fmt_is_planar(self.sample_fmt))
81+
return bool(lib.av_sample_fmt_is_planar(self.sample_fmt))
8282

83-
property is_packed:
83+
@property
84+
def is_packed(self):
8485
"""Is this a planar format?
8586
8687
Strictly opposite of :attr:`is_planar`.
8788
8889
"""
89-
def __get__(self):
90-
return not lib.av_sample_fmt_is_planar(self.sample_fmt)
90+
return not lib.av_sample_fmt_is_planar(self.sample_fmt)
9191

92-
property planar:
92+
@property
93+
def planar(self):
9394
"""The planar variant of this format.
9495
9596
Is itself when planar:
9697
98+
>>> from av import AudioFormat as Format
9799
>>> fmt = Format('s16p')
98100
>>> fmt.planar is fmt
99101
True
100102
101103
"""
102-
def __get__(self):
103-
if self.is_planar:
104-
return self
105-
return get_audio_format(lib.av_get_planar_sample_fmt(self.sample_fmt))
104+
if self.is_planar:
105+
return self
106+
return get_audio_format(lib.av_get_planar_sample_fmt(self.sample_fmt))
106107

107-
property packed:
108+
@property
109+
def packed(self):
108110
"""The packed variant of this format.
109111
110112
Is itself when packed:
@@ -114,30 +116,29 @@ cdef class AudioFormat:
114116
True
115117
116118
"""
117-
def __get__(self):
118-
if self.is_packed:
119-
return self
120-
return get_audio_format(lib.av_get_packed_sample_fmt(self.sample_fmt))
119+
if self.is_packed:
120+
return self
121+
return get_audio_format(lib.av_get_packed_sample_fmt(self.sample_fmt))
121122

122-
property container_name:
123+
@property
124+
def container_name(self):
123125
"""The name of a :class:`ContainerFormat` which directly accepts this data.
124126
125127
:raises ValueError: when planar, since there are no such containers.
126128
127129
"""
128-
def __get__(self):
129-
if self.is_planar:
130-
raise ValueError("no planar container formats")
131-
132-
if self.sample_fmt == lib.AV_SAMPLE_FMT_U8:
133-
return "u8"
134-
elif self.sample_fmt == lib.AV_SAMPLE_FMT_S16:
135-
return "s16" + container_format_postfix
136-
elif self.sample_fmt == lib.AV_SAMPLE_FMT_S32:
137-
return "s32" + container_format_postfix
138-
elif self.sample_fmt == lib.AV_SAMPLE_FMT_FLT:
139-
return "f32" + container_format_postfix
140-
elif self.sample_fmt == lib.AV_SAMPLE_FMT_DBL:
141-
return "f64" + container_format_postfix
142-
143-
raise ValueError("unknown layout")
130+
if self.is_planar:
131+
raise ValueError("no planar container formats")
132+
133+
if self.sample_fmt == lib.AV_SAMPLE_FMT_U8:
134+
return "u8"
135+
elif self.sample_fmt == lib.AV_SAMPLE_FMT_S16:
136+
return "s16" + container_format_postfix
137+
elif self.sample_fmt == lib.AV_SAMPLE_FMT_S32:
138+
return "s32" + container_format_postfix
139+
elif self.sample_fmt == lib.AV_SAMPLE_FMT_FLT:
140+
return "f32" + container_format_postfix
141+
elif self.sample_fmt == lib.AV_SAMPLE_FMT_DBL:
142+
return "f64" + container_format_postfix
143+
144+
raise ValueError("unknown layout")

av/audio/frame.pyx

+15-13
Original file line numberDiff line numberDiff line change
@@ -141,34 +141,36 @@ cdef class AudioFrame(Frame):
141141

142142
return tuple([AudioPlane(self, i) for i in range(plane_count)])
143143

144-
property samples:
144+
@property
145+
def samples(self):
145146
"""
146147
Number of audio samples (per channel).
147148
148149
:type: int
149150
"""
150-
def __get__(self):
151-
return self.ptr.nb_samples
151+
return self.ptr.nb_samples
152152

153-
property sample_rate:
153+
@property
154+
def sample_rate(self):
154155
"""
155156
Sample rate of the audio data, in samples per second.
156157
157158
:type: int
158159
"""
159-
def __get__(self):
160-
return self.ptr.sample_rate
160+
return self.ptr.sample_rate
161161

162-
def __set__(self, value):
163-
self.ptr.sample_rate = value
162+
@sample_rate.setter
163+
def sample_rate(self, value):
164+
self.ptr.sample_rate = value
164165

165-
property rate:
166+
@property
167+
def rate(self):
166168
"""Another name for :attr:`sample_rate`."""
167-
def __get__(self):
168-
return self.ptr.sample_rate
169+
return self.ptr.sample_rate
169170

170-
def __set__(self, value):
171-
self.ptr.sample_rate = value
171+
@rate.setter
172+
def rate(self, value):
173+
self.ptr.sample_rate = value
172174

173175
def to_ndarray(self, **kwargs):
174176
"""Get a numpy array of this frame.

av/audio/layout.pyx

+12-12
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ cdef class AudioLayout:
9393
def __repr__(self):
9494
return f"<av.{self.__class__.__name__} {self.name!r}>"
9595

96-
property name:
96+
@property
97+
def name(self):
9798
"""The canonical name of the audio layout."""
98-
def __get__(self):
99-
cdef char out[32]
100-
# Passing 0 as number of channels... fix this later?
101-
lib.av_get_channel_layout_string(out, 32, 0, self.layout)
102-
return <str>out
99+
cdef char out[32]
100+
# Passing 0 as number of channels... fix this later?
101+
lib.av_get_channel_layout_string(out, 32, 0, self.layout)
102+
return <str>out
103103

104104

105105
cdef class AudioChannel:
@@ -109,12 +109,12 @@ cdef class AudioChannel:
109109
def __repr__(self):
110110
return f"<av.{self.__class__.__name__} {self.name!r} ({self.description})>"
111111

112-
property name:
112+
@property
113+
def name(self):
113114
"""The canonical name of the audio channel."""
114-
def __get__(self):
115-
return lib.av_get_channel_name(self.channel)
115+
return lib.av_get_channel_name(self.channel)
116116

117-
property description:
117+
@property
118+
def description(self):
118119
"""A human description of the audio channel."""
119-
def __get__(self):
120-
return channel_descriptions.get(self.name)
120+
return channel_descriptions.get(self.name)

0 commit comments

Comments
 (0)