Skip to content

Commit a19764e

Browse files
committed
mypy
1 parent 994d2ec commit a19764e

File tree

6 files changed

+25
-19
lines changed

6 files changed

+25
-19
lines changed

packages/models-library/src/models_library/function_services_catalog/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def add(
5252
raises ValueError
5353
"""
5454
if not isinstance(meta, ServiceMetaDataPublished):
55-
msg = f"Expected ServiceDockerData, got {type(meta)}"
55+
msg = f"Expected ServiceDockerData, got {type(meta)}" # type: ignore[unreachable]
5656
raise ValueError(msg)
5757

5858
# ensure unique

packages/models-library/src/models_library/progress_bar.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Literal, TypeAlias
1+
from typing import Final, Literal, TypeAlias
22

33
from pydantic import BaseModel, ConfigDict
44

@@ -43,7 +43,7 @@ class ProgressStructuredMessage(BaseModel):
4343
)
4444

4545

46-
UNITLESS = None
46+
UNITLESS: Final[None] = None
4747

4848

4949
class ProgressReport(BaseModel):
@@ -96,7 +96,11 @@ def composed_message(self) -> str:
9696
{
9797
"actual_value": 0.3,
9898
"total": 1.0,
99-
"message": ProgressStructuredMessage.model_config["json_schema_extra"]["examples"][2], # type: ignore [index]
99+
"message": ProgressStructuredMessage.model_config[
100+
"json_schema_extra"
101+
]["examples"][
102+
2
103+
], # type: ignore [index]
100104
},
101105
]
102106
},

packages/models-library/src/models_library/service_settings_labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def _ensure_callbacks_mapping_container_names_defined_in_compose_spec(
518518
cls, v: CallbacksMapping, info: ValidationInfo
519519
):
520520
if v is None:
521-
return {}
521+
return {} # type: ignore[unreachable]
522522

523523
defined_services: set[str] = {x.service for x in v.before_shutdown}
524524
if v.metrics:

packages/models-library/src/models_library/services_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,5 @@ def validate(cls, v: "ServiceRunID | str", _: ValidationInfo) -> "ServiceRunID":
9797
return v
9898
if isinstance(v, str):
9999
return cls(v)
100-
msg = f"Invalid value for RunID: {v}"
100+
msg = f"Invalid value for RunID: {v}" # type: ignore[unreachable]
101101
raise TypeError(msg)

packages/models-library/src/models_library/utils/_original_fastapi_encoders.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
#
66
import dataclasses
77
from collections import defaultdict, deque
8+
from collections.abc import Callable
89
from enum import Enum
910
from pathlib import PurePath
1011
from types import GeneratorType
11-
from typing import Any, Callable, Union, get_origin
12+
from typing import Annotated, Any, Union, get_origin
1213

1314
from common_library.json_serialization import ENCODERS_BY_TYPE
1415
from pydantic import BaseModel
1516
from pydantic_core import PydanticUndefined, PydanticUndefinedType
16-
from typing_extensions import Annotated, Doc
17+
from typing_extensions import Doc
1718

1819
Undefined = PydanticUndefined
1920
UndefinedType = PydanticUndefinedType
@@ -142,14 +143,13 @@ def jsonable_encoder(
142143
if custom_encoder:
143144
if type(obj) in custom_encoder:
144145
return custom_encoder[type(obj)](obj)
145-
else:
146-
for encoder_type, encoder_instance in custom_encoder.items():
147-
if isinstance(obj, encoder_type):
148-
return encoder_instance(obj)
149-
if include is not None and not isinstance(include, (set, dict)):
150-
include = set(include)
151-
if exclude is not None and not isinstance(exclude, (set, dict)):
152-
exclude = set(exclude)
146+
for encoder_type, encoder_instance in custom_encoder.items():
147+
if isinstance(obj, encoder_type):
148+
return encoder_instance(obj)
149+
if include is not None and not isinstance(include, set | dict):
150+
include = set(include) # type: ignore[unreachable]
151+
if exclude is not None and not isinstance(exclude, set | dict):
152+
exclude = set(exclude) # type: ignore[unreachable]
153153
if isinstance(obj, BaseModel):
154154
obj_dict = BaseModel.model_dump(
155155
obj,

packages/models-library/src/models_library/utils/common_validators.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MyModel(BaseModel):
2727

2828

2929
def trim_string_before(max_length: int) -> BeforeValidator:
30-
def _trim(value: str):
30+
def _trim(value: str | Any) -> str | Any:
3131
if isinstance(value, str):
3232
return value[:max_length]
3333
return value
@@ -125,14 +125,16 @@ def _validator(cls: type[BaseModel], values):
125125
}
126126

127127
if not functools.reduce(operator.xor, (v is not None for v in got.values())):
128-
msg = f"Either { ' or '.join(got.keys()) } must be set, but not both. Got {got}"
128+
msg = (
129+
f"Either {' or '.join(got.keys())} must be set, but not both. Got {got}"
130+
)
129131
raise ValueError(msg)
130132
return values
131133

132134
return _validator
133135

134136

135-
def to_camel_recursive(data: dict[str, Any]) -> dict[str, Any]:
137+
def to_camel_recursive(data: dict[str, Any] | Any) -> dict[str, Any] | Any:
136138
"""Recursively convert dictionary keys to camelCase"""
137139
if not isinstance(data, dict):
138140
return data # Return as-is if it's not a dictionary

0 commit comments

Comments
 (0)