diff --git a/openlibrary/catalog/marc/marc_xml.py b/openlibrary/catalog/marc/marc_xml.py index fce892a222c..ed3f767b6b9 100644 --- a/openlibrary/catalog/marc/marc_xml.py +++ b/openlibrary/catalog/marc/marc_xml.py @@ -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) diff --git a/openlibrary/core/lists/model.py b/openlibrary/core/lists/model.py index 1946338466e..121986c5673 100644 --- a/openlibrary/core/lists/model.py +++ b/openlibrary/core/lists/model.py @@ -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:"): diff --git a/openlibrary/coverstore/code.py b/openlibrary/coverstore/code.py index ce41c31191f..27d374b2446 100644 --- a/openlibrary/coverstore/code.py +++ b/openlibrary/coverstore/code.py @@ -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 diff --git a/openlibrary/plugins/importapi/code.py b/openlibrary/plugins/importapi/code.py index 34d65a6a614..1463d0cc962 100644 --- a/openlibrary/plugins/importapi/code.py +++ b/openlibrary/plugins/importapi/code.py @@ -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 diff --git a/openlibrary/plugins/openlibrary/lists.py b/openlibrary/plugins/openlibrary/lists.py index 7cf2631956d..add74b35154 100644 --- a/openlibrary/plugins/openlibrary/lists.py +++ b/openlibrary/plugins/openlibrary/lists.py @@ -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(): diff --git a/pyproject.toml b/pyproject.toml index 0c9aa1f72bf..cbc3a000dbf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,7 +49,6 @@ ignore = [ "F841", "PERF401", "PIE790", - "PLR5501", "PLW0602", "PLW0603", "PLW2901",