Skip to content

Commit

Permalink
fix some r-s and s-s warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sfoster1 committed Dec 3, 2024
1 parent a26b495 commit f3c812c
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion robot-server/robot_server/persistence/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def pydantic_to_json(obj: BaseModel) -> str:

def pydantic_list_to_json(obj_list: Sequence[BaseModel]) -> str:
"""Serialize a list of Pydantic objects for storing in the SQL database."""
return json.dumps([obj.dict(by_alias=True, exclude_none=True) for obj in obj_list])
return json.dumps([obj.model_dump(by_alias=True, exclude_none=True) for obj in obj_list])


# TODO: It would be nice to type this function as (Type[_BasemodelT] | TypeAdapter[_BaseModelT]) -> _BaseModelT,
Expand Down
1 change: 1 addition & 0 deletions robot-server/robot_server/runs/run_store.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Runs' on-db store."""

import logging
from collections import defaultdict
from dataclasses import dataclass
Expand Down
2 changes: 1 addition & 1 deletion robot-server/robot_server/service/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(
*wrapped_details,
),
links=links,
).dict(exclude_none=True)
).model_dump(exclude_none=True)

super().__init__(
status_code=definition.status_code,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def get_wifi_networks(
"letting the system decide when to do a rescan."
),
),
] = False
] = False,
) -> WifiNetworks:
networks = await nmcli.available_ssids(rescan)
return WifiNetworks(list=[WifiNetworkFull(**n) for n in networks])
Expand Down Expand Up @@ -190,7 +190,7 @@ async def post_wifi_key(key: UploadFile = File(...)):
else:
# We return a JSONResponse because we want the 200 status code.
response.message = "Key file already present"
return JSONResponse(content=response.dict())
return JSONResponse(content=response.model_dump())


@router.delete(
Expand All @@ -210,7 +210,7 @@ async def delete_wifi_key(
description="The ID of key to delete, as determined by a previous"
" call to GET /wifi/keys",
),
]
],
) -> V1BasicResponse:
"""Delete wifi key handler"""
deleted_file = wifi.remove_key(key_uuid)
Expand Down Expand Up @@ -274,4 +274,4 @@ async def post_wifi_disconnect(wifi_ssid: WifiNetwork):
)
else:
stat = status.HTTP_500_INTERNAL_SERVER_ERROR
return JSONResponse(status_code=stat, content=result.dict())
return JSONResponse(status_code=stat, content=result.model_dump())
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def execute(self, command: Command) -> CompletedCommand:
with duration() as time_it:
name_arg = command.request.command
data = command.request.data
data_arg = data.dict() if data else {}
data_arg = data.model_dump() if data else {}

await self._callable(name_arg, data_arg)

Expand Down
6 changes: 3 additions & 3 deletions robot-server/tests/service/json_api/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ def test_attributes_as_dict():
DictRequest = RequestModel[dict]
obj_to_validate = {"data": {"some_data": 1}}
my_request_obj = DictRequest.model_validate(obj_to_validate)
assert my_request_obj.dict() == {"data": {"some_data": 1}}
assert my_request_obj.model_dump() == {"data": {"some_data": 1}}


def test_attributes_as_item_model():
ItemRequest = RequestModel[ItemModel]
obj_to_validate = {"data": {"name": "apple", "quantity": 10, "price": 1.20}}
my_request_obj = ItemRequest.model_validate(obj_to_validate)
assert my_request_obj.dict() == obj_to_validate
assert my_request_obj.model_dump() == obj_to_validate


def test_attributes_as_item_model_empty_dict():
Expand Down Expand Up @@ -91,6 +91,6 @@ def test_request_with_id():
"data": {"type": "item", "attributes": {}, "id": "abc123"},
}
my_request_obj = MyRequest.model_validate(obj_to_validate)
assert my_request_obj.dict() == {
assert my_request_obj.model_dump() == {
"data": {"type": "item", "attributes": {}, "id": "abc123"},
}
2 changes: 1 addition & 1 deletion robot-server/tests/service/json_api/test_resource_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_follows_structure():
}
}
validated = ThingWithLink.model_validate(structure_to_validate)
assert validated.dict() == structure_to_validate
assert validated.model_dump() == structure_to_validate


def test_must_be_self_key_with_string_value():
Expand Down
2 changes: 1 addition & 1 deletion robot-server/tests/service/json_api/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ class ResponseSpec(NamedTuple):

@pytest.mark.parametrize(ResponseSpec._fields, RESPONSE_SPECS)
def test_response_to_dict(subject: BaseModel, expected: Dict[str, Any]) -> None:
assert subject.dict() == expected
assert subject.model_dump() == expected
2 changes: 1 addition & 1 deletion system-server/system_server/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def save_settings(settings: SystemServerSettings) -> bool:
env_path = env_path or f"{settings.persistence_directory}/system.env"
prefix = settings.model_config.get("env_prefix")
try:
for key, val in settings.dict().items():
for key, val in settings.model_dump().items():
name = f"{prefix}{key}"
value = str(val) if val is not None else ""
set_key(env_path, name, value)
Expand Down

0 comments on commit f3c812c

Please sign in to comment.