Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Commit 33b8c5e

Browse files
lgeigerafrozenator
authored andcommitted
Prefer literals over list and dict functions (#1454)
* d = dict() --> d = {} * l = list() --> []
1 parent 3f4a997 commit 33b8c5e

File tree

11 files changed

+15
-15
lines changed

11 files changed

+15
-15
lines changed

tensor2tensor/data_generators/audio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _collect_data(directory, input_ext, target_ext):
6060
# if the datafile was "/path/to/datafile.wav" then the key would be
6161
# "/path/to/datafile"
6262
# value: a pair of strings (input_filepath, target_filepath)
63-
data_files = dict()
63+
data_files = {}
6464
for root, _, filenames in os.walk(directory):
6565
input_files = [filename for filename in filenames if input_ext in filename]
6666
for input_filename in input_files:

tensor2tensor/data_generators/gym_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ def __init__(self, base_env_name=None, batch_size=1, grayscale=False,
640640

641641
if self.should_derive_observation_space:
642642
with self._tf_graph.obj.as_default():
643-
self._resize = dict()
643+
self._resize = {}
644644
orig_height, orig_width = orig_observ_space.shape[:2]
645645
self._img_batch_t = _Noncopyable(tf.placeholder(
646646
dtype=tf.uint8, shape=(None, orig_height, orig_width, 3)))

tensor2tensor/data_generators/gym_env_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def setUp(self):
8484
def init_batch_and_play(self, env_name, steps_per_epoch=1, epochs=(0,),
8585
generate_data=False, batch_size=2, **kwargs):
8686
env = gym_env.T2TGymEnv(env_name, batch_size=batch_size, **kwargs)
87-
obs = list()
88-
rewards = list()
87+
obs = []
88+
rewards = []
8989
num_dones = 0
9090
for epoch in epochs:
9191
env.start_new_epoch(epoch, self.out_dir)
@@ -100,8 +100,8 @@ def init_batch_and_play(self, env_name, steps_per_epoch=1, epochs=(0,),
100100
return env, obs, rewards, num_dones
101101

102102
def play(self, env, n_steps):
103-
obs = list()
104-
rewards = list()
103+
obs = []
104+
rewards = []
105105
obs.append(env.reset())
106106
num_dones = 0
107107
for _ in range(n_steps):

tensor2tensor/data_generators/librispeech.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _collect_data(directory, input_ext, transcription_ext):
6767
# if the datafile was "/path/to/datafile.wav" then the key would be
6868
# "/path/to/datafile"
6969
# value: a pair of strings (media_filepath, label)
70-
data_files = dict()
70+
data_files = {}
7171
for root, _, filenames in os.walk(directory):
7272
transcripts = [filename for filename in filenames
7373
if transcription_ext in filename]

tensor2tensor/data_generators/mscoco.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def get_vocab():
107107
caption_file = io.open(caption_filepath)
108108
caption_json = json.load(caption_file)
109109
# Dictionary from image_id to ((filename, height, width), captions).
110-
image_dict = dict()
110+
image_dict = {}
111111
for image in caption_json["images"]:
112112
image_dict[image["id"]] = [(image["file_name"], image["height"],
113113
image["width"]), []]

tensor2tensor/models/research/attention_lm_moe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def print_shape(x, suffix, debug=False):
308308
x,
309309
hparams.filter_size)
310310
else:
311-
additional_conv_params = dict()
311+
additional_conv_params = {}
312312
if hparams.use_sepconv:
313313
additional_conv_params = dict(
314314
padding="LEFT",

tensor2tensor/rl/player_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def infer_paths(output_dir, **subdirs):
389389
Returns:
390390
a dictionary with the directories.
391391
"""
392-
directories = dict()
392+
directories = {}
393393
for name, path in six.iteritems(subdirs):
394394
directories[name] = path if path else os.path.join(output_dir, name)
395395
directories["output_dir"] = output_dir

tensor2tensor/utils/hparam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ def parse(self, values):
495495
ValueError: If `values` cannot be parsed or a hyperparameter in `values`
496496
doesn't exist.
497497
"""
498-
type_map = dict()
498+
type_map = {}
499499
for name, t in self._hparam_types.items():
500500
param_type, _ = t
501501
type_map[name] = param_type

tensor2tensor/utils/metrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ def image_wrapped_metric_fn(predictions,
600600
def weights_fn_for_mp(problem_task_id):
601601
return lambda x: common_layers.weights_multi_problem(x, problem_task_id)
602602

603-
eval_metrics = dict()
603+
eval_metrics = {}
604604
for problem_instance in problems:
605605
problem_name = problem_instance.name
606606
if problem_instance.was_reversed:
@@ -681,7 +681,7 @@ def create_eager_metrics_internal(metric_fns,
681681
(accum_fn(predictions, targets) => None,
682682
result_fn() => dict<str metric_name, float avg_val>
683683
"""
684-
tfe_metrics = dict()
684+
tfe_metrics = {}
685685

686686
for name in metric_fns:
687687
tfe_metrics[name] = tfe.metrics.Mean(name=name)

tensor2tensor/utils/rouge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _lcs(x, y):
6262
Table of dictionary of coord and len lcs
6363
"""
6464
n, m = len(x), len(y)
65-
table = dict()
65+
table = {}
6666
for i in range(n + 1):
6767
for j in range(m + 1):
6868
if i == 0 or j == 0:

0 commit comments

Comments
 (0)