Skip to content

Commit

Permalink
Clean up class name and self in calls to super()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mbrukman committed Dec 30, 2022
1 parent d1500aa commit 11b0c18
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions keras_nlp/layers/transformer_decoder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_value_error_when_invalid_kernel_inititalizer(self):
def test_one_training_step_of_transformer_with_cross_attention(self):
class MyModel(keras.Model):
def __init__(self):
super(MyModel, self).__init__()
super().__init__()
self._decoder = transformer_decoder.TransformerDecoder(
intermediate_dim=4, num_heads=2
)
Expand Down Expand Up @@ -160,7 +160,7 @@ def call(self, decoder_input, encoder_output):
def test_one_training_step_of_transformer_without_cross_attention(self):
class MyModel(keras.Model):
def __init__(self):
super(MyModel, self).__init__()
super().__init__()
self._decoder = transformer_decoder.TransformerDecoder(
intermediate_dim=4,
num_heads=2,
Expand Down

0 comments on commit 11b0c18

Please sign in to comment.