Skip to content

Commit c344e55

Browse files
authored
Enable more linting and type checking (#62)
1 parent d618e29 commit c344e55

14 files changed

+2019
-51
lines changed

pyproject.toml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,24 @@ build-backend = "uv_build"
5050
[tool.ruff]
5151
exclude = [
5252
"examples",
53+
".devcontainer",
5354
]
5455

5556
[tool.ruff.lint]
5657
# Full list of rules here: https://docs.astral.sh/ruff/rules/
5758
select = [
5859
# Core rules
59-
# "E", # pycodestyle errors
60+
"E", # pycodestyle errors
6061
"F", # Pyflakes
61-
# "UP", # pyupgrade
62+
"UP", # pyupgrade
6263
"I", # isort
6364

6465
# Quality and style
65-
# "B", # flake8-bugbear
66+
"B", # flake8-bugbear
6667
"Q", # flake8-quotes
67-
# "SIM", # flake8-simplify
68+
"SIM", # flake8-simplify
6869
"FLY", # flynt
69-
# "PERF", # Perflint
70+
"PERF", # Perflint
7071

7172
# Disabled rules (uncomment to enable):
7273
# "AIR", # Airflow
@@ -130,7 +131,10 @@ select = [
130131
# =============================================================================
131132

132133
[tool.pyright]
133-
include = ["src"]
134+
include = [
135+
"src",
136+
"tests",
137+
]
134138

135139

136140
# =============================================================================

src/streetview/api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from io import BytesIO
2-
from typing import Dict, Union
32

43
import requests
54
from PIL import Image
@@ -64,8 +63,8 @@ def get_streetview(
6463
"""
6564

6665
url = "https://maps.googleapis.com/maps/api/streetview"
67-
params: Dict[str, Union[str, int]] = {
68-
"size": "%dx%d" % (width, height),
66+
params: dict[str, str | int] = {
67+
"size": f"{width:.0f}x{height:.0f}",
6968
"fov": fov,
7069
"pitch": pitch,
7170
"heading": heading,

src/streetview/download.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import concurrent.futures
33
import itertools
44
import time
5+
from collections.abc import AsyncGenerator, Generator
56
from dataclasses import dataclass
67
from io import BytesIO
7-
from typing import AsyncGenerator, Generator, Tuple
88

99
import httpx
1010
import requests
@@ -30,7 +30,7 @@ class Tile:
3030
image: Image.Image
3131

3232

33-
def get_width_and_height_from_zoom(zoom: int) -> Tuple[int, int]:
33+
def get_width_and_height_from_zoom(zoom: int) -> tuple[int, int]:
3434
"""
3535
Returns the width and height of a panorama at a given zoom level, depends on the
3636
zoom level.
@@ -58,7 +58,7 @@ def fetch_panorama_tile(
5858
try:
5959
response = requests.get(tile_info.fileurl, stream=True)
6060
return Image.open(BytesIO(response.content))
61-
except requests.ConnectionError:
61+
except requests.ConnectionError: # noqa: PERF203
6262
print("Connection error. Trying again in 2 seconds.")
6363
time.sleep(2)
6464
raise requests.ConnectionError("Max retries exceeded.")
@@ -75,7 +75,7 @@ async def fetch_panorama_tile_async(
7575
response = await async_client.get(tile_info.fileurl)
7676
return Image.open(BytesIO(response.content))
7777

78-
except httpx.RequestError as e:
78+
except httpx.RequestError as e: # noqa: PERF203
7979
print(f"Request error {e}. Trying again in 2 seconds.")
8080
await asyncio.sleep(2)
8181

@@ -117,9 +117,8 @@ def iter_tiles(
117117
try:
118118
image = future.result()
119119
except Exception as exc:
120-
raise Exception(
121-
f"Failed to download tile {info.fileurl} due to Exception: {exc}"
122-
)
120+
msg = f"Failed to download tile {info.fileurl} due to Exception: {exc}"
121+
raise Exception(msg) from exc
123122
else:
124123
yield Tile(x=info.x, y=info.y, image=image)
125124

src/streetview/search.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import re
3-
from typing import List, Optional
43

54
import requests
65
from pydantic import BaseModel
@@ -12,10 +11,10 @@ class Panorama(BaseModel):
1211
lat: float
1312
lon: float
1413
heading: float
15-
pitch: Optional[float]
16-
roll: Optional[float]
17-
date: Optional[str]
18-
elevation: Optional[float]
14+
pitch: float | None
15+
roll: float | None
16+
date: str | None
17+
elevation: float | None
1918

2019

2120
def make_search_url(lat: float, lon: float) -> str:
@@ -43,7 +42,7 @@ def search_request(lat: float, lon: float) -> Response:
4342
return requests.get(url)
4443

4544

46-
def extract_panoramas(text: str) -> List[Panorama]:
45+
def extract_panoramas(text: str) -> list[Panorama]:
4746
"""
4847
Given a valid response from the panoids endpoint, return a list of all the
4948
panoids.
@@ -61,10 +60,7 @@ def extract_panoramas(text: str) -> List[Panorama]:
6160

6261
raw_panos = subset[3][0]
6362

64-
if len(subset) < 9 or subset[8] is None:
65-
raw_dates = []
66-
else:
67-
raw_dates = subset[8]
63+
raw_dates = [] if (len(subset) < 9 or subset[8] is None) else subset[8]
6864

6965
# For some reason, dates do not include a date for each panorama.
7066
# the n dates match the last n panos. Here we flip the arrays
@@ -89,7 +85,7 @@ def extract_panoramas(text: str) -> List[Panorama]:
8985
]
9086

9187

92-
def search_panoramas(lat: float, lon: float) -> List[Panorama]:
88+
def search_panoramas(lat: float, lon: float) -> list[Panorama]:
9389
"""
9490
Gets the closest panoramas (ids) to the GPS coordinates.
9591
"""

tests/cassettes/TestPanodsOnLocations.test_that_dates_are_correct[location0].yaml

Lines changed: 542 additions & 0 deletions
Large diffs are not rendered by default.

tests/cassettes/TestPanodsOnLocations.test_that_dates_are_correct[location1].yaml

Lines changed: 1025 additions & 0 deletions
Large diffs are not rendered by default.

tests/cassettes/TestPanodsOnLocations.test_that_panoids_are_unique[location0].yaml

Lines changed: 65 additions & 0 deletions
Large diffs are not rendered by default.

tests/cassettes/TestPanodsOnLocations.test_that_panoids_are_unique[location1].yaml

Lines changed: 71 additions & 0 deletions
Large diffs are not rendered by default.

tests/cassettes/TestPanodsOnLocations.test_that_there_are_the_expected_number_of_results[location0].yaml

Lines changed: 65 additions & 0 deletions
Large diffs are not rendered by default.

tests/cassettes/TestPanodsOnLocations.test_that_there_are_the_expected_number_of_results[location1].yaml

Lines changed: 71 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)