Skip to content

Commit

Permalink
Exclude banks with empty bic in BIC.from_bank_code
Browse files Browse the repository at this point in the history
  • Loading branch information
mdomke committed Jun 10, 2024
1 parent 3de4b0d commit bd6527c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions schwifty/bic.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def candidates_from_bank_code(cls, country_code: str, bank_code: str) -> list[BI
banks = sorted(
index[(country_code, bank_code)], key=itemgetter("primary"), reverse=True
)
return [cls(entry["bic"]) for entry in banks]
return [cls(entry["bic"]) for entry in banks if entry["bic"]]
except KeyError as e:
raise exceptions.InvalidBankCode(
f"Unknown bank code {bank_code!r} for country {country_code!r}"
Expand Down Expand Up @@ -249,7 +249,7 @@ def from_bank_code(cls, country_code: str, bank_code: str) -> BIC:
if generic_codes:
return sorted(generic_codes)[-1]
return candidates[0]
except KeyError as e:
except (KeyError, IndexError) as e:
raise exceptions.InvalidBankCode(
f"Unknown bank code {bank_code!r} for country {country_code!r}"
) from e
Expand Down

0 comments on commit bd6527c

Please sign in to comment.