Skip to content

Commit de2ed78

Browse files
committed
WIP: fix linter warnings
1 parent f686728 commit de2ed78

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

src/api/qualicharge/api/v1/routers/static.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""QualiCharge API v1 statique router."""
22

33
import logging
4-
from typing import Annotated, List, Optional
4+
from typing import Annotated, List, Optional, cast
55

66
from annotated_types import Len
77
from fastapi import APIRouter, Depends, HTTPException, Path, Query, Request, status
88
from pydantic import AnyHttpUrl, BaseModel, computed_field
99
from sqlalchemy import func
10+
from sqlalchemy.schema import Column as SAColumn
1011
from sqlmodel import Session, select
1112

1213
from qualicharge.conf import settings
@@ -75,7 +76,7 @@ async def list(
7576
"""List statique items."""
7677
current_url = request.url
7778
previous_url = next_url = None
78-
total = session.exec(select(func.count(PointDeCharge.id_pdc_itinerance))).one()
79+
total = session.exec(select(func.count(cast(SAColumn, PointDeCharge.id)))).one()
7980
statiques = [statique for statique in list_statique(session, offset, limit)]
8081

8182
previous_offset = offset - limit if offset > limit else 0

src/api/qualicharge/schemas/static.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def set_geometry_point(cls, value: Coordinate, info: ValidationInfo) -> str:
139139

140140
@field_serializer("coordonneesXY")
141141
def serialize_coordonneesXY(
142-
self, value: Union[str, Geometry], _
142+
self, value: Union[str, WKBElement], _
143143
) -> Union[str, Coordinate]:
144144
"""Serialize coordonneesXY field.
145145

src/api/qualicharge/schemas/utils.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""QualiCharge schemas utilities."""
22

33
import logging
4-
from typing import Generator, List, NamedTuple, Optional, Set, Tuple, Type
4+
from typing import Generator, List, NamedTuple, Optional, Set, Tuple, Type, cast
55

66
from sqlalchemy import func
77
from sqlalchemy.exc import MultipleResultsFound
8+
from sqlalchemy.schema import Column as SAColumn
89
from sqlmodel import Session, SQLModel, select
910

1011
from ..exceptions import (
@@ -153,7 +154,7 @@ def save_statique(session: Session, statique: Statique) -> Statique:
153154
session.commit()
154155
session.refresh(pdc)
155156

156-
return pdc_to_statique(pdc)
157+
return pdc_to_statique(cast(PointDeCharge, pdc))
157158

158159

159160
def update_statique(
@@ -169,7 +170,7 @@ def update_statique(
169170
# Check that the statique to update exists
170171
if (
171172
session.exec(
172-
select(func.count(PointDeCharge.id)).where(
173+
select(func.count(cast(SAColumn, PointDeCharge.id))).where(
173174
PointDeCharge.id_pdc_itinerance == id_pdc_itinerance
174175
)
175176
).one()
@@ -192,7 +193,7 @@ def save_statiques(
192193
# Ignore already existing PDC
193194
db_pdcs = session.exec(
194195
select(PointDeCharge.id_pdc_itinerance).filter(
195-
PointDeCharge.id_pdc_itinerance.in_(submitted_pdcs)
196+
cast(SAColumn, PointDeCharge.id_pdc_itinerance).in_(submitted_pdcs)
196197
)
197198
).all()
198199
statiques = list(filter(lambda s: s.id_pdc_itinerance not in db_pdcs, statiques))
@@ -232,7 +233,10 @@ class StatiqueSchemasEntryIndex(NamedTuple):
232233
enseigne = Enseigne(**statique.get_fields_for_schema(Enseigne))
233234
localisation = Localisation(**statique.get_fields_for_schema(Localisation))
234235

235-
indexes = ()
236+
indexes = []
237+
# FIXME
238+
# Looks like mypy does not recognize types for tuple of tuples to unpack,
239+
# ignored unrelevant typing errors.
236240
for entry, entries in (
237241
(pdc, points_de_charge),
238242
(station, stations),
@@ -241,12 +245,16 @@ class StatiqueSchemasEntryIndex(NamedTuple):
241245
(enseigne, enseignes),
242246
(localisation, localisations),
243247
):
244-
if entry not in entries:
245-
entries.append(entry)
246-
indexes += (entries.index(entry),)
248+
if entry not in entries: # type: ignore[operator]
249+
entries.append(entry) # type: ignore[attr-defined]
250+
indexes.append(entries.index(entry)) # type: ignore[attr-defined]
247251
statiques_db_refs.append(StatiqueSchemasEntryIndex(*indexes))
248252

249253
# Create database entries for each schema
254+
#
255+
# FIXME
256+
# Looks like mypy does not recognize types for tuple of tuples to unpack,
257+
# ignored unrelevant typing errors.
250258
for entries, fields in (
251259
(points_de_charge, {"id_pdc_itinerance"}),
252260
(stations, {"id_station_itinerance"}),
@@ -255,12 +263,12 @@ class StatiqueSchemasEntryIndex(NamedTuple):
255263
(enseignes, None),
256264
(localisations, {"adresse_station"}),
257265
):
258-
for idx, entry in enumerate(entries):
266+
for idx, entry in enumerate(entries): # type: ignore[arg-type]
259267
_, db_entry = get_or_create(
260268
session, entry, fields, add=False, commit=False, refresh=False
261269
)
262-
entries[idx] = db_entry
263-
session.add_all(entries)
270+
entries[idx] = db_entry # type: ignore[index]
271+
session.add_all(entries) # type: ignore[arg-type]
264272

265273
# Handle relationships
266274
for (

src/api/tests/api/v1/routers/test_statique.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_list(client_auth, db_session):
1616
assert response.status_code == status.HTTP_200_OK
1717
json_response = response.json()
1818
assert json_response == {
19-
"limit": 10,
19+
"limit": 100,
2020
"offset": 0,
2121
"previous": None,
2222
"next": None,
@@ -35,7 +35,7 @@ def test_list(client_auth, db_session):
3535
assert response.status_code == status.HTTP_200_OK
3636
json_response = response.json()
3737
assert json_response == {
38-
"limit": 10,
38+
"limit": 100,
3939
"offset": 0,
4040
"previous": None,
4141
"next": None,
@@ -50,8 +50,8 @@ def test_list_pagination(client_auth, db_session):
5050
n_statiques = 3
5151
list(save_statiques(db_session, StatiqueFactory.batch(n_statiques)))
5252

53-
offset: int = 0
54-
limit: int = 2
53+
offset = 0
54+
limit = 2
5555
response = client_auth.get(f"/statique/?{offset=}&{limit=}")
5656
assert response.status_code == status.HTTP_200_OK
5757
json_response = response.json()

0 commit comments

Comments
 (0)