Skip to content

Use 'key in dict' instead of 'key in dict.keys()' #4017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion installer/fix_qt5_rpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def fix_rpath(PATH):
# Loop through all dependencies of each library/executable
raw_output = subprocess.Popen(["oTool", "-L", file_path], stdout=subprocess.PIPE).communicate()[0].decode('utf-8')
for output in raw_output.split("\n")[1:-1]:
if output and not "is not an object file" in output and ".o):" not in output:
if output and "is not an object file" not in output and ".o):" not in output:
dependency_path = output.split('\t')[1].split(' ')[0]
dependency_version = output.split('\t')[1].split(' (')[1].replace(')', '')
dependency_base_path, dependency_name = os.path.split(dependency_path)
Expand Down
6 changes: 3 additions & 3 deletions src/classes/project_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def get(self, key):
# True until something disqualifies this as a match
match = True
# Check each key in key_part dictionary and if not found to be equal as a property in item, move on to next item in list
for subkey in key_part.keys():
for subkey in key_part:
# Get each key in dictionary (i.e. "id", "layer", etc...)
subkey = subkey.lower()
# If object is missing the key or the values differ, then it doesn't match.
Expand Down Expand Up @@ -512,7 +512,7 @@ def read_legacy_project_file(self, file_path):
for track in reversed(sequence.tracks):
for clip in track.clips:
# Get associated file for this clip
if clip.file_object.unique_id in file_lookup.keys():
if clip.file_object.unique_id in file_lookup:
file = file_lookup[clip.file_object.unique_id]
else:
# Skip missing file
Expand Down Expand Up @@ -840,7 +840,7 @@ def move_temp_paths_to_project_folder(self, file_path, previous_path=None):
log.info("Checking clip {} path for file {}".format(clip["id"], file_id))
# Update paths to files stored in our working space or old path structure
# (should have already been copied during previous File stage)
if file_id and file_id in reader_paths.keys():
if file_id and file_id in reader_paths:
clip["reader"]["path"] = reader_paths[file_id]
log.info("Updated clip {} path for file {}".format(clip["id"], file_id))

Expand Down
4 changes: 2 additions & 2 deletions src/language/generate_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@
# Loop through props
for key in props.keys():
object = props[key]
if "name" in object.keys():
if "name" in object:
effects_text[object["name"]] = "libopenshot (Clip Properties)"
if "choices" in object.keys():
if "choices" in object:
for choice in object["choices"]:
effects_text[choice["name"]] = "libopenshot (Clip Properties)"

Expand Down
4 changes: 2 additions & 2 deletions src/windows/add_to_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ def accept(self):
start_time = 0
end_time = new_clip["reader"]["duration"]

if 'start' in file.data.keys():
if 'start' in file.data:
start_time = file.data['start']
new_clip["start"] = start_time
if 'end' in file.data.keys():
if 'end' in file.data:
end_time = file.data['end']
new_clip["end"] = end_time

Expand Down
4 changes: 2 additions & 2 deletions src/windows/cutting.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __init__(self, file=None, preview=False):

# Determine if a start or end attribute is in this file
start_frame = 1
if 'start' in self.file.data.keys():
if 'start' in self.file.data:
start_frame = (float(self.file.data['start']) * self.fps) + 1

# Display start frame (and then the previous frame)
Expand Down Expand Up @@ -334,7 +334,7 @@ def btnAddClip_clicked(self):
log.info('btnAddClip_clicked')

# Remove unneeded attributes
if 'name' in self.file.data.keys():
if 'name' in self.file.data:
self.file.data.pop('name')

# Save new file
Expand Down
4 changes: 2 additions & 2 deletions src/windows/file_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ def __init__(self, file):
fps_float = float(self.file.data["fps"]["num"]) / float(self.file.data["fps"]["den"])

tags = ""
if "tags" in self.file.data.keys():
if "tags" in self.file.data:
tags = self.file.data["tags"]
name = filename
if "name" in self.file.data.keys():
if "name" in self.file.data:
name = self.file.data["name"]

# Populate fields
Expand Down
2 changes: 1 addition & 1 deletion src/windows/models/add_to_timeline_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def update_model(self, files=[], clear=True):

# Look for friendly name attribute (optional)
name = filename
if 'name' in file.data.keys():
if 'name' in file.data:
name = file.data['name']

# Append thumbnail
Expand Down
8 changes: 4 additions & 4 deletions src/windows/models/files_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ def update_model(self, clear=True, delete_file_id=None):

path, filename = os.path.split(file.data["path"])
tags = ""
if "tags" in file.data.keys():
if "tags" in file.data:
tags = file.data["tags"]
name = filename
if "name" in file.data.keys():
if "name" in file.data:
name = file.data["name"]

media_type = file.data.get("media_type")
Expand All @@ -183,7 +183,7 @@ def update_model(self, clear=True, delete_file_id=None):
if media_type in ["video", "image"]:
# Check for start and end attributes (optional)
thumbnail_frame = 1
if 'start' in file.data.keys():
if 'start' in file.data:
fps = file.data["fps"]
fps_float = float(fps["num"]) / float(fps["den"])
thumbnail_frame = round(float(file.data['start']) * fps_float) + 1
Expand Down Expand Up @@ -493,7 +493,7 @@ def update_file_thumbnail(self, file_id):
file = File.get(id=file_id)
path, filename = os.path.split(file.data["path"])
name = filename
if "name" in file.data.keys():
if "name" in file.data:
name = file.data["name"]

# Refresh thumbnail for updated file
Expand Down
2 changes: 1 addition & 1 deletion src/windows/views/files_treeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def value_updated(self, item):
else:
f.data["name"] = os.path.basename(f.data["path"])

if "tags" in f.data.keys():
if "tags" in f.data:
if tags != f.data["tags"]:
f.data["tags"] = tags
elif tags:
Expand Down
8 changes: 4 additions & 4 deletions src/windows/views/webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2227,7 +2227,7 @@ def Time_Triggered(self, action, clip_ids, speed="1X", playhead_position=0.0):
continue

# Keep original 'end' and 'duration'
if "original_data" not in clip.data.keys():
if "original_data" not in clip.data:
clip.data["original_data"] = {
"end": clip.data["end"],
"duration": clip.data["duration"],
Expand All @@ -2246,7 +2246,7 @@ def Time_Triggered(self, action, clip_ids, speed="1X", playhead_position=0.0):
freeze_seconds = float(speed)

original_duration = clip.data["duration"]
if "original_data" in clip.data.keys():
if "original_data" in clip.data:
original_duration = clip.data["original_data"]["duration"]

log.info('Updating timing for clip ID {}, original duration: {}'
Expand Down Expand Up @@ -2873,9 +2873,9 @@ def callback(self, data, callback_data):
return # Do nothing

# Check for optional start and end attributes
if 'start' in file.data.keys():
if 'start' in file.data:
new_clip["start"] = file.data['start']
if 'end' in file.data.keys():
if 'end' in file.data:
new_clip["end"] = file.data['end']

# Set position and closet track
Expand Down