Skip to content

Commit

Permalink
Switch class definitions to py3 conventions.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 387224410
  • Loading branch information
fchollet authored and tensorflower-gardener committed Jul 27, 2021
1 parent 67637b1 commit 0dc8e73
Show file tree
Hide file tree
Showing 56 changed files with 135 additions and 135 deletions.
2 changes: 1 addition & 1 deletion keras/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2143,7 +2143,7 @@ def test_function_tf_run_options_with_run_metadata(self):

def test_function_fetch_callbacks(self):

class CallbackStub(object):
class CallbackStub:

def __init__(self):
self.times_called = 0
Expand Down
2 changes: 1 addition & 1 deletion keras/benchmarks/distribution_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def get_strategy_scope(strategy):
return strategy_scope


class DummyContextManager(object):
class DummyContextManager:

def __enter__(self):
pass
Expand Down
8 changes: 4 additions & 4 deletions keras/callbacks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ def test_EarlyStopping_with_baseline(self):

def test_EarlyStopping_final_weights_when_restoring_model_weights(self):

class DummyModel(object):
class DummyModel:

def __init__(self):
self.stop_training = False
Expand Down Expand Up @@ -1415,12 +1415,12 @@ def make_model():

def test_ReduceLROnPlateau_patience(self):

class DummyOptimizer(object):
class DummyOptimizer:

def __init__(self):
self.lr = keras.backend.variable(1.0)

class DummyModel(object):
class DummyModel:

def __init__(self):
self.optimizer = DummyOptimizer()
Expand Down Expand Up @@ -2015,7 +2015,7 @@ def on_train_batch_end(self, batch, logs=None):
_ObservedSummary = collections.namedtuple('_ObservedSummary', ('logdir', 'tag'))


class _SummaryFile(object):
class _SummaryFile:
"""A record of summary tags and the files to which they were written.
Fields `scalars`, `images`, `histograms`, and `tensors` are sets
Expand Down
8 changes: 4 additions & 4 deletions keras/callbacks_v1_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def callbacks_factory(histogram_freq):

def test_Tensorboard_histogram_summaries_in_test_function(self):

class FileWriterStub(object):
class FileWriterStub:

def __init__(self, logdir, graph=None):
self.logdir = logdir
Expand Down Expand Up @@ -387,7 +387,7 @@ def test_TensorBoard_with_ReduceLROnPlateau(self):

def test_Tensorboard_batch_logging(self):

class FileWriterStub(object):
class FileWriterStub:

def __init__(self, logdir, graph=None):
self.logdir = logdir
Expand Down Expand Up @@ -422,7 +422,7 @@ def close(self):

def test_Tensorboard_epoch_and_batch_logging(self):

class FileWriterStub(object):
class FileWriterStub:

def __init__(self, logdir, graph=None):
self.logdir = logdir
Expand Down Expand Up @@ -496,7 +496,7 @@ def test_Tensorboard_eager(self):

def test_TensorBoard_update_freq(self):

class FileWriterStub(object):
class FileWriterStub:

def __init__(self, logdir, graph=None):
self.logdir = logdir
Expand Down
2 changes: 1 addition & 1 deletion keras/distribute/ctl_correctness_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
_STEPS_PER_EPOCH = 2


class MaybeStrategyScope(object):
class MaybeStrategyScope:
"""Provides a context allowing no distribution strategy."""

def __init__(self, strategy):
Expand Down
6 changes: 3 additions & 3 deletions keras/distribute/distribute_coordinator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_current_worker_context():
return None


class _TaskType(object):
class _TaskType:
PS = "ps"
WORKER = "worker"
CHIEF = "chief"
Expand All @@ -63,7 +63,7 @@ def _get_num_workers(cluster_spec):
cluster_spec.as_dict().get(_TaskType.CHIEF, []))


class _WorkerContext(object):
class _WorkerContext:
"""The worker context class.
This context object provides configuration information for each task. One
Expand Down Expand Up @@ -377,7 +377,7 @@ def _run_std_server(cluster_spec=None,
if rpc_layer:
target = rpc_layer + "://" + target

class _FakeServer(object):
class _FakeServer:
"""A fake server that runs a master session."""

def start(self):
Expand Down
8 changes: 4 additions & 4 deletions keras/distribute/distributed_file_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@

class DistributedFileUtilsTest(tf.test.TestCase):

class MockedExtended(object):
class MockedExtended:
pass

class MockedChiefStrategy(object):
class MockedChiefStrategy:

def __init__(self):
self.extended = DistributedFileUtilsTest.MockedExtended()
self.extended._in_multi_worker_mode = lambda: True
self.extended.should_checkpoint = True

class MockedWorkerStrategy(object):
class MockedWorkerStrategy:

def __init__(self):
self.extended = DistributedFileUtilsTest.MockedExtended()
self.extended._in_multi_worker_mode = lambda: True
self.extended.should_checkpoint = False
self.extended._task_id = 3

class MockedSingleWorkerStrategy(object):
class MockedSingleWorkerStrategy:

def __init__(self):
self.extended = DistributedFileUtilsTest.MockedExtended()
Expand Down
2 changes: 1 addition & 1 deletion keras/distribute/keras_correctness_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def multi_worker_mirrored_eager_and_graph():
eager_mode_test_configuration() + graph_mode_test_configuration())


class MaybeDistributionScope(object):
class MaybeDistributionScope:
"""Provides a context allowing no distribution strategy."""

def __init__(self, distribution):
Expand Down
2 changes: 1 addition & 1 deletion keras/distribute/sidecar_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def list_checkpoint_attributes(ckpt_dir_or_file):


@keras_export('keras.experimental.SidecarEvaluator', v1=[])
class SidecarEvaluator(object):
class SidecarEvaluator:
"""A class designed for a dedicated evaluator task.
`SidecarEvaluator` is expected to be run in a process on a separate machine
Expand Down
2 changes: 1 addition & 1 deletion keras/distribute/worker_training_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
CKPT_SAVED_EPOCH_UNUSED_VALUE = -1


class WorkerTrainingState(object):
class WorkerTrainingState:
"""Training state management class.
This class provides apis for backing up and restoring the training state.
Expand Down
6 changes: 3 additions & 3 deletions keras/engine/base_layer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def call_context():
tf.__internal__.register_call_context_function(call_context)


class CallContext(object):
class CallContext:
"""Keeps track of properties currently inside a Layer/Model's `call`.
Attributes:
Expand Down Expand Up @@ -512,7 +512,7 @@ def in_keras_graph(self):
getattr(backend.get_graph(), 'name', None) == 'keras_graph')


class CallContextManager(object):
class CallContextManager:
"""Context manager for `CallContext`."""

def __init__(self, call_ctx, state):
Expand Down Expand Up @@ -769,7 +769,7 @@ def v2_dtype_behavior_enabled():
return V2_DTYPE_BEHAVIOR


class TrackableWeightHandler(object):
class TrackableWeightHandler:
"""Keras wrapper for handling tracking.Trackable object saving and restoring.
This class handles Trackables in both V1 and V2 modes, ensuring that they can
Expand Down
2 changes: 1 addition & 1 deletion keras/engine/compile_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from keras.utils import tf_utils


class Container(object):
class Container:
"""Base Container class."""

def __init__(self, output_names=None):
Expand Down
4 changes: 2 additions & 2 deletions keras/engine/compile_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def test_custom_loss_callables(self):
def custom_loss_fn(y_true, y_pred):
return tf.reduce_sum(y_true - y_pred)

class CustomLossClass(object):
class CustomLossClass:

def __call__(self, y_true, y_pred):
return tf.reduce_sum(y_true - y_pred)
Expand Down Expand Up @@ -771,7 +771,7 @@ def test_custom_metric_callables(self):
def custom_metric_fn(y_true, y_pred):
return tf.reduce_sum(y_true - y_pred)

class CustomMetricClass(object):
class CustomMetricClass:

def __call__(self, y_true, y_pred):
return tf.reduce_sum(y_true - y_pred)
Expand Down
2 changes: 1 addition & 1 deletion keras/engine/data_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ def broadcast_sample_weight_modes(target_structure, sample_weight_modes):
return sample_weight_modes


class DataHandler(object):
class DataHandler:
"""Handles iterating over epoch-level `tf.data.Iterator` objects."""

def __init__(self,
Expand Down
2 changes: 1 addition & 1 deletion keras/engine/data_adapter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from keras.utils import data_utils


class DummyArrayLike(object):
class DummyArrayLike:
"""Dummy array-like object."""

def __init__(self, data):
Expand Down
4 changes: 2 additions & 2 deletions keras/engine/functional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ class Double(layers.Layer):
def call(self, x1, kwarg=None):
return x1 + x1

class NonSerializable(object):
class NonSerializable:

def __init__(self, foo=None):
self.foo = foo
Expand Down Expand Up @@ -2443,7 +2443,7 @@ def __init__(self, *args, **kwargs):
super().__init__(inputs=[my_input], outputs=outputs, *args, **kwargs)


class MixinClass(object):
class MixinClass:

def __init__(self, foo, **kwargs):
self._foo = foo
Expand Down
2 changes: 1 addition & 1 deletion keras/engine/input_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
v1=['keras.layers.InputSpec',
'keras.__internal__.legacy.layers.InputSpec'])
@tf_export(v1=['layers.InputSpec'])
class InputSpec(object):
class InputSpec:
"""Specifies the rank, dtype and shape of every input to a layer.
Layers can expose (if appropriate) an `input_spec` attribute:
Expand Down
4 changes: 2 additions & 2 deletions keras/engine/keras_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
_MAX_TENSOR_RANK = 254


class KerasTensor(object):
class KerasTensor:
"""A representation of a Keras in/output during Functional API construction.
`KerasTensor`s are tensor-like objects that represent the symbolic inputs
Expand Down Expand Up @@ -535,7 +535,7 @@ def _to_placeholder(self):
return self._user_registered_symbolic_object


class _KerasTensorIterator(object):
class _KerasTensorIterator:
"""Iterates over the leading dim of a KerasTensor. Performs 0 error checks."""

def __init__(self, tensor, dim0):
Expand Down
2 changes: 1 addition & 1 deletion keras/engine/partial_batch_padding_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from keras import backend


class PartialBatchPaddingHandler(object):
class PartialBatchPaddingHandler:
"""A container that holds info about partial batches for `predict()`."""

def __init__(self, output_shape):
Expand Down
2 changes: 1 addition & 1 deletion keras/engine/training_dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def test_finite_dataset_unknown_cardinality_no_steps_arg(self):
@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
def test_finite_dataset_unknown_cardinality_no_step_with_train_and_val(self):

class CaptureStdout(object):
class CaptureStdout:

def __enter__(self):
self._stdout = sys.stdout
Expand Down
2 changes: 1 addition & 1 deletion keras/engine/training_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def handle_partial_sample_weights(outputs, sample_weights, sample_weight_modes,
any_sample_weight, partial_sample_weight)


class RespectCompiledTrainableState(object):
class RespectCompiledTrainableState:
"""Set and restore trainable state if it has changed since compile.
The keras API guarantees that the value of each Layer's `trainable` property
Expand Down
4 changes: 2 additions & 2 deletions keras/engine/training_utils_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ def infer_steps_for_dataset(model,
return steps


class ModelInputs(object):
class ModelInputs:
"""Encapsulates model inputs.
Allows for transforming model inputs while keeping the same structure.
Expand Down Expand Up @@ -1885,7 +1885,7 @@ def unpack_validation_data(validation_data, raise_if_ambiguous=True):
return val_x, val_y, val_sample_weight


class TrainingLoop(object):
class TrainingLoop:
"""TrainingLoop is a wrapper class around the training logic.
This class is trying to encapsulate the different logic of fit/eval/predict
Expand Down
6 changes: 3 additions & 3 deletions keras/engine/training_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
# ==============================================================================
"""V1 Training-related part of the Keras engine."""

# pylint: disable=g-classes-have-attributes
import tensorflow.compat.v2 as tf

import collections
Expand Down Expand Up @@ -2867,7 +2867,7 @@ def __getattr__(self, item):
return super(DistributedCallbackModel, self).__getattr__(item)


class _TrainingEndpoint(object):
class _TrainingEndpoint:
"""A container for the training output/target and related entities.
In the case of model with multiple outputs, there is a one-to-one mapping
Expand Down Expand Up @@ -3099,7 +3099,7 @@ def populate_sample_weight(self, sample_weight, sample_weight_mode):
name=self.output_name + '_sample_weights')


class _TrainingTarget(object):
class _TrainingTarget:
"""Container for a target tensor (y_true) and its metadata (shape, loss...).
Args:
Expand Down
4 changes: 2 additions & 2 deletions keras/initializers/initializers_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


@keras_export('keras.initializers.Initializer')
class Initializer(object):
class Initializer:
"""Initializer base class: all Keras initializers inherit from this class.
Initializers should implement a `__call__` method with the following
Expand Down Expand Up @@ -943,7 +943,7 @@ def _assert_float_dtype(dtype):
return dtype


class _RandomGenerator(object):
class _RandomGenerator:
"""Random generator that selects appropriate random ops."""

def __init__(self, seed=None):
Expand Down
2 changes: 1 addition & 1 deletion keras/layers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
from keras.layers.serialization import serialize


class VersionAwareLayers(object):
class VersionAwareLayers:
"""Utility to be used internally to access layers in a V1/V2-aware fashion.
When using layers within the Keras codebase, under the constraint that
Expand Down
Loading

0 comments on commit 0dc8e73

Please sign in to comment.