Skip to content

Commit

Permalink
Minor optimizations based on pointers from perflint
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinbjornt committed Sep 26, 2023
1 parent edfcfa2 commit f0a89b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/iceaddr/postcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,8 @@ def _filter_postcodes(key: str, searchstr: str, partial: bool = False) -> List[i
k1 = key + "_nf"
k2 = key + "_tgf"

for k, v in POSTCODES.items():
pcs = POSTCODES.items()
for k, v in pcs:
nf = v[k1].lower()
tgf = v[k2].lower()
if (partial and (nf.startswith(p) or tgf.startswith(p))) or p in (nf, tgf):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_iceaddr.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@

def test_address_lookup():
"""Test address lookup using various known addresses."""
ADDR_TO_POSTCODE = [
ADDR_TO_POSTCODE = (
("Öldugata", 4, "Reykjavík", 101),
("öldugötu", 12, "hafnarfirði", 220),
("Tómasarhaga", 12, "Reykjavík", 107),
("smiðjuvegur", 22, "", 200),
]
)

for a in ADDR_TO_POSTCODE:
res = iceaddr_lookup(a[0], number=a[1], placename=a[2])
Expand All @@ -45,7 +45,7 @@ def test_address_lookup():
res = iceaddr_lookup("Brattagata", number=4, letter="b")
assert res and res[0]["postnr"] == 310 and res[0]["stadur_nf"] == "Borgarnes"

POSTCODE_TO_PLACENAME = [
POSTCODE_TO_PLACENAME = (
("Öldugata", 4, 101, "Reykjavík", "Höfuðborgarsvæðið", "Þéttbýli"),
(
"dagverðardalur",
Expand All @@ -56,7 +56,7 @@ def test_address_lookup():
"Þéttbýli",
),
("Höfðabraut", 3, 805, "Selfoss", "Suðurland og Reykjanes", "Stærra dreifbýli"),
]
)

for p in POSTCODE_TO_PLACENAME:
# print(f"iceaddr_lookup('{p[0]}', number={p[1]}, postcode={p[2]}"
Expand Down

0 comments on commit f0a89b3

Please sign in to comment.