Skip to content
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

Enable PLR5501 - Convert nested if statements to elif clauses for better readability #10260

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions openlibrary/catalog/marc/marc_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ def read_fields(self, want: list[str]) -> Iterator[tuple[str, str | DataField]]:
continue
if not tag.isdigit():
non_digit = True
else:
if tag[0] != '9' and non_digit:
raise BadSubtag
elif tag[0] != '9' and non_digit:
raise BadSubtag
if f.attrib['tag'] not in want:
continue
yield f.attrib['tag'], self.decode_field(f)
Expand Down
7 changes: 3 additions & 4 deletions openlibrary/core/lists/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,10 @@ def title(self) -> str:
def url(self):
if self.document:
return self.document.url()
elif self.key.startswith("subject:"):
return "/subjects/" + web.lstrips(self.key, "subject:")
else:
if self.key.startswith("subject:"):
return "/subjects/" + web.lstrips(self.key, "subject:")
else:
return "/subjects/" + self.key
return "/subjects/" + self.key

def get_subject_url(self, subject: SeedSubjectString) -> str:
if subject.startswith("subject:"):
Expand Down
17 changes: 8 additions & 9 deletions openlibrary/coverstore/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,14 @@ def _query(category, key, value):
if category in prefixes:
olkey = prefixes[category] + value
return get_cover_id([olkey])
else:
if category == 'b':
if key == 'isbn':
value = value.replace("-", "").strip()
key = "isbn_"
if key == 'oclc':
key = 'oclc_numbers'
olkeys = ol_things(key, value)
return get_cover_id(olkeys)
elif category == 'b':
if key == 'isbn':
value = value.replace("-", "").strip()
key = "isbn_"
if key == 'oclc':
key = 'oclc_numbers'
olkeys = ol_things(key, value)
return get_cover_id(olkeys)
return None


Expand Down
21 changes: 10 additions & 11 deletions openlibrary/plugins/importapi/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,18 +659,17 @@ def format_result(self, matches, authenticated, keys):
d[i] = identifiers[i]
d.update(doc)

elif authenticated:
d = {'status': 'created', 'works': [], 'authors': [], 'editions': []}
for i in keys:
if i.startswith('/books'):
d['editions'].append(i)
if i.startswith('/works'):
d['works'].append(i)
if i.startswith('/authors'):
d['authors'].append(i)
else:
if authenticated:
d = {'status': 'created', 'works': [], 'authors': [], 'editions': []}
for i in keys:
if i.startswith('/books'):
d['editions'].append(i)
if i.startswith('/works'):
d['works'].append(i)
if i.startswith('/authors'):
d['authors'].append(i)
else:
d = {'status': 'notfound'}
d = {'status': 'notfound'}
return d


Expand Down
27 changes: 13 additions & 14 deletions openlibrary/plugins/openlibrary/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,20 @@ def normalize_input_seed(
return seed
else:
return {'key': olid_to_key(seed)}
else:
if 'thing' in seed:
annotated_seed = cast(AnnotatedSeedDict, seed) # Appease mypy

if is_empty_annotated_seed(annotated_seed):
return ListRecord.normalize_input_seed(annotated_seed['thing'])
elif annotated_seed['thing']['key'].startswith('/subjects/'):
return subject_key_to_seed(annotated_seed['thing']['key'])
else:
return annotated_seed
elif seed['key'].startswith('/subjects/'):
thing_ref = cast(ThingReferenceDict, seed) # Appease mypy
return subject_key_to_seed(thing_ref['key'])
elif 'thing' in seed:
annotated_seed = cast(AnnotatedSeedDict, seed) # Appease mypy

if is_empty_annotated_seed(annotated_seed):
return ListRecord.normalize_input_seed(annotated_seed['thing'])
elif annotated_seed['thing']['key'].startswith('/subjects/'):
return subject_key_to_seed(annotated_seed['thing']['key'])
else:
return seed
return annotated_seed
elif seed['key'].startswith('/subjects/'):
thing_ref = cast(ThingReferenceDict, seed) # Appease mypy
return subject_key_to_seed(thing_ref['key'])
else:
return seed

@staticmethod
def from_input():
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ ignore = [
"F841",
"PERF401",
"PIE790",
"PLR5501",
"PLW0602",
"PLW0603",
"PLW2901",
Expand Down
Loading