Skip to content

Commit 6540dfd

Browse files
committed
add warn_unreachable to mypy
1 parent 197b746 commit 6540dfd

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

fitbit_client/resources/nutrition.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def create_food(
6161
calories: int,
6262
description: str,
6363
form_type: FoodFormType,
64-
nutritional_values: Dict[NutritionalValue, float],
64+
nutritional_values: Dict[NutritionalValue | str, float | int],
6565
user_id: str = "-",
6666
debug: bool = False,
6767
) -> JSONDict:
@@ -98,11 +98,10 @@ def create_food(
9898
and NutritionalValue.CALORIES_FROM_FAT in nutritional_values
9999
and not isinstance(nutritional_values[NutritionalValue.CALORIES_FROM_FAT], int)
100100
):
101-
raise ValidationException(
101+
raise ClientValidationException(
102102
message="Calories from fat must be an integer",
103-
status_code=400,
104-
error_type="validation",
105-
field_name="caloriesFromFat",
103+
error_type="client_validation",
104+
field_name="CALORIES_FROM_FAT",
106105
)
107106
# Handle both enum and string nutritional values
108107
for key, value in nutritional_values.items():

pyproject.toml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,35 +110,28 @@ strict_optional = true
110110
warn_redundant_casts = true
111111
warn_unused_ignores = true
112112
warn_no_return = true
113-
# warn_unreachable = true
113+
warn_unreachable = true
114114
# disallow_any_generics = true
115115
disallow_subclassing_any = true
116116
disallow_untyped_calls = true
117-
118-
# Show details about error locations
119-
# show_column_numbers = true
117+
# output formatting
120118
show_error_codes = true
121119
pretty = true
122120
error_summary = true
123121
show_error_context = true
124-
# show_traceback = true
125-
126122

127-
# Necessary for most libraries
128123
[[tool.mypy.overrides]]
129124
module = [
130125
"requests.*",
131126
"requests_oauthlib.*",
132-
"pytest.*",
133-
"pyOpenSSL.*"
134127
]
135128
ignore_missing_imports = true
136129

137130

138131
[tool.pdm.scripts]
139132
autoflake = { cmd = "autoflake . -r --remove-unused-variables --remove-all-unused-imports --ignore-pass-after-docstring --exclude ./.venv/*,./_scripts/*" }
140133
headers = { cmd = "python lint/add_file_headers.py" }
141-
typecheck = { cmd = "mypy --show-error-codes --pretty --no-incremental fitbit_client" }
134+
mypy = { cmd = "mypy --pretty --no-incremental --warn-unused-configs fitbit_client" }
142135
black = { cmd = "black ." }
143136
isort = { cmd = "isort ." }
144137
mdformat = { cmd = "mdformat ." }

tests/resources/nutrition/test_create_food.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pytest import raises
77

88
# Local imports
9+
from fitbit_client.exceptions import ClientValidationException
910
from fitbit_client.exceptions import ValidationException
1011
from fitbit_client.resources.constants import FoodFormType
1112
from fitbit_client.resources.constants import NutritionalValue
@@ -82,7 +83,7 @@ def test_create_food_with_string_nutritional_values(nutrition_resource, mock_res
8283

8384
def test_create_food_calories_from_fat_must_be_integer(nutrition_resource):
8485
"""Test that calories_from_fat must be an integer"""
85-
with raises(ValidationException) as exc_info:
86+
with raises(ClientValidationException) as exc_info:
8687
nutrition_resource.create_food(
8788
name="Test Food",
8889
default_food_measurement_unit_id=147,
@@ -98,7 +99,6 @@ def test_create_food_calories_from_fat_must_be_integer(nutrition_resource):
9899
) # Float instead of integer
99100

100101
# Verify exception details
101-
assert exc_info.value.status_code == 400
102-
assert exc_info.value.error_type == "validation"
103-
assert exc_info.value.field_name == "caloriesFromFat"
102+
assert exc_info.value.error_type == "client_validation"
103+
assert exc_info.value.field_name == "CALORIES_FROM_FAT"
104104
assert "Calories from fat must be an integer" in str(exc_info.value)

0 commit comments

Comments
 (0)