Skip to content
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
3 changes: 3 additions & 0 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
- name: Check code format with Ruff
run: uv run ruff format --check us

- name: Check types with ty
run: uv run ty check us

testing:
needs: linting
runs-on: ubuntu-latest
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ dependencies = ['jellyfish']
states = "us.cli.states:main"

[dependency-groups]
dev = ['ruff', 'pytest', 'pytz']
dev = [
'ruff',
'pytest',
'pytz',
"ty>=0.0.38",
]

[tool.ruff]
line-length = 120
Expand Down
6 changes: 4 additions & 2 deletions us/cli/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ def main():

sys.stdout.write("\n")
sys.stdout.write(" shapefiles:\n")
for region, url in state.shapefile_urls().items():
sys.stdout.write(" %s: %s\n" % (region, url))
urls = state.shapefile_urls()
if urls is not None:
for region, url in urls.items():
sys.stdout.write(" %s: %s\n" % (region, url))

sys.stdout.write("\n")

Expand Down
3 changes: 1 addition & 2 deletions us/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Any, Callable, Dict, Iterable, List, Optional, Type
from urllib.parse import urljoin

import jellyfish # type: ignore
import jellyfish

FIPS_RE = re.compile(r"^\d{2}$")
ABBR_RE = re.compile(r"^[a-zA-Z]{2}$")
Expand Down Expand Up @@ -137,7 +137,6 @@ def lookup(
# fallback results are cached under a separate, fallback-specific key so
# they never leak into non-fallback lookups -- or lookups using a
# different fallback -- of the same value
fallback_key = None
if fallback_func is not None:
fallback_key = f"{cache_key}:fallback:{fallback_func!r}"
if use_cache and fallback_key in _lookup_cache:
Expand Down
14 changes: 10 additions & 4 deletions us/tests/test_us.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import re
from itertools import chain

import jellyfish # type: ignore
import pytest # type: ignore
import jellyfish
import pytest
import pytz

import us
Expand Down Expand Up @@ -251,10 +251,15 @@ def test_dc():

@pytest.mark.skip
def test_head():
import requests
# `requests` is intentionally not declared as a dependency; this test
# is permanently skipped and the import is dead code for ty.
import requests # ty: ignore[unresolved-import]

for state in us.STATES_AND_TERRITORIES:
for url in state.shapefile_urls().values():
urls = state.shapefile_urls()
if urls is None:
continue
for url in urls.values():
resp = requests.head(url)
assert resp.status_code == 200

Expand Down Expand Up @@ -312,6 +317,7 @@ def test_county_fips_format():

def test_county_fips_prefixed_by_state():
for state in us.STATES_AND_TERRITORIES:
assert state.fips is not None, f"{state.abbr}: missing state fips"
for county in state.counties:
assert county.fips.startswith(state.fips), (
f"{state.abbr}: county {county.name} fips {county.fips} not prefixed by state fips {state.fips}"
Expand Down
27 changes: 27 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.