Skip to content

Commit a3c5fc0

Browse files
authored
Clean up class name and self in calls to super() (#1182)
PEP 3135 [^1] simplified the syntax for `super()` in Python 3.0 from: super(ClassName, self) to the following very simple and equivalent [^2] syntax: super() The current Keras codebase already requires Python 3+, and there's a mix of the two syntax formats above, sometimes both are used in a single file. This change simplifies the entire code base by cleaning up the remaining explicit uses of the current class name and `self` and using the cleaner `super()` syntax everywhere consistently. Since the new syntax is intended to be a shorthand for the old syntax, this change should have no semantic differences from before. [^1]: https://peps.python.org/pep-3135/ [^2]: https://docs.python.org/3/library/functions.html#super
1 parent e40fab4 commit a3c5fc0

File tree

182 files changed

+514
-514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+514
-514
lines changed

examples/audio/ipynb/melgan_spectrogram_inversion.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
" return audio\n",
244244
"\n",
245245
" def get_config(self):\n",
246-
" config = super(MelSpec, self).get_config()\n",
246+
" config = super().get_config()\n",
247247
" config.update(\n",
248248
" {\n",
249249
" \"frame_length\": self.frame_length,\n",

examples/audio/ipynb/wav2vec2_audiocls.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@
423423
" \"\"\"Combines the encoder and decoder into an end-to-end model for training.\"\"\"\n",
424424
"\n",
425425
" def __init__(self, model_checkpoint, num_classes):\n",
426-
" super(TFWav2Vec2ForAudioClassification, self).__init__()\n",
426+
" super().__init__()\n",
427427
" # Instantiate the Wav2Vec 2.0 model without the Classification-Head\n",
428428
" self.wav2vec2 = TFWav2Vec2Model.from_pretrained(\n",
429429
" model_checkpoint, apply_spec_augment=False, from_pt=True\n",

examples/audio/md/melgan_spectrogram_inversion.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class MelSpec(layers.Layer):
208208
return audio
209209

210210
def get_config(self):
211-
config = super(MelSpec, self).get_config()
211+
config = super().get_config()
212212
config.update(
213213
{
214214
"frame_length": self.frame_length,

examples/audio/md/wav2vec2_audiocls.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class TFWav2Vec2ForAudioClassification(layers.Layer):
314314
"""Combines the encoder and decoder into an end-to-end model for training."""
315315

316316
def __init__(self, model_checkpoint, num_classes):
317-
super(TFWav2Vec2ForAudioClassification, self).__init__()
317+
super().__init__()
318318
# Instantiate the Wav2Vec 2.0 model without the Classification-Head
319319
self.wav2vec2 = TFWav2Vec2Model.from_pretrained(
320320
model_checkpoint, apply_spec_augment=False, from_pt=True

examples/audio/melgan_spectrogram_inversion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def call(self, audio, training=True):
166166
return audio
167167

168168
def get_config(self):
169-
config = super(MelSpec, self).get_config()
169+
config = super().get_config()
170170
config.update(
171171
{
172172
"frame_length": self.frame_length,

examples/audio/wav2vec2_audiocls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class TFWav2Vec2ForAudioClassification(layers.Layer):
270270
"""Combines the encoder and decoder into an end-to-end model for training."""
271271

272272
def __init__(self, model_checkpoint, num_classes):
273-
super(TFWav2Vec2ForAudioClassification, self).__init__()
273+
super().__init__()
274274
# Instantiate the Wav2Vec 2.0 model without the Classification-Head
275275
self.wav2vec2 = TFWav2Vec2Model.from_pretrained(
276276
model_checkpoint, apply_spec_augment=False, from_pt=True

examples/generative/conditional_gan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153

154154
class ConditionalGAN(keras.Model):
155155
def __init__(self, discriminator, generator, latent_dim):
156-
super(ConditionalGAN, self).__init__()
156+
super().__init__()
157157
self.discriminator = discriminator
158158
self.generator = generator
159159
self.latent_dim = latent_dim
@@ -165,7 +165,7 @@ def metrics(self):
165165
return [self.gen_loss_tracker, self.disc_loss_tracker]
166166

167167
def compile(self, d_optimizer, g_optimizer, loss_fn):
168-
super(ConditionalGAN, self).compile()
168+
super().compile()
169169
self.d_optimizer = d_optimizer
170170
self.g_optimizer = g_optimizer
171171
self.loss_fn = loss_fn

examples/generative/cyclegan.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class ReflectionPadding2D(layers.Layer):
156156

157157
def __init__(self, padding=(1, 1), **kwargs):
158158
self.padding = tuple(padding)
159-
super(ReflectionPadding2D, self).__init__(**kwargs)
159+
super().__init__(**kwargs)
160160

161161
def call(self, input_tensor, mask=None):
162162
padding_width, padding_height = self.padding
@@ -401,7 +401,7 @@ def __init__(
401401
lambda_cycle=10.0,
402402
lambda_identity=0.5,
403403
):
404-
super(CycleGan, self).__init__()
404+
super().__init__()
405405
self.gen_G = generator_G
406406
self.gen_F = generator_F
407407
self.disc_X = discriminator_X
@@ -426,7 +426,7 @@ def compile(
426426
gen_loss_fn,
427427
disc_loss_fn,
428428
):
429-
super(CycleGan, self).compile()
429+
super().compile()
430430
self.gen_G_optimizer = gen_G_optimizer
431431
self.gen_F_optimizer = gen_F_optimizer
432432
self.disc_X_optimizer = disc_X_optimizer

examples/generative/dcgan_overriding_train_step.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@
110110

111111
class GAN(keras.Model):
112112
def __init__(self, discriminator, generator, latent_dim):
113-
super(GAN, self).__init__()
113+
super().__init__()
114114
self.discriminator = discriminator
115115
self.generator = generator
116116
self.latent_dim = latent_dim
117117

118118
def compile(self, d_optimizer, g_optimizer, loss_fn):
119-
super(GAN, self).compile()
119+
super().compile()
120120
self.d_optimizer = d_optimizer
121121
self.g_optimizer = g_optimizer
122122
self.loss_fn = loss_fn

examples/generative/ipynb/conditional_gan.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256
"\n",
257257
"class ConditionalGAN(keras.Model):\n",
258258
" def __init__(self, discriminator, generator, latent_dim):\n",
259-
" super(ConditionalGAN, self).__init__()\n",
259+
" super().__init__()\n",
260260
" self.discriminator = discriminator\n",
261261
" self.generator = generator\n",
262262
" self.latent_dim = latent_dim\n",
@@ -268,7 +268,7 @@
268268
" return [self.gen_loss_tracker, self.disc_loss_tracker]\n",
269269
"\n",
270270
" def compile(self, d_optimizer, g_optimizer, loss_fn):\n",
271-
" super(ConditionalGAN, self).compile()\n",
271+
" super().compile()\n",
272272
" self.d_optimizer = d_optimizer\n",
273273
" self.g_optimizer = g_optimizer\n",
274274
" self.loss_fn = loss_fn\n",

0 commit comments

Comments
 (0)