Skip to content

Commit ceea505

Browse files
committed
chore: changes for mypy update
Signed-off-by: Cody Edwards <[email protected]>
1 parent f0a6f57 commit ceea505

File tree

7 files changed

+46
-17
lines changed

7 files changed

+46
-17
lines changed

hatch.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pre-install-commands = [
55

66
[envs.default.scripts]
77
sync = "pip install -r requirements-testing.txt"
8-
test = "pytest --cov-config pyproject.toml {args:test}"
8+
test = "pytest --cov-config pyproject.toml {args:test} -vv"
99
typing = "mypy {args:src test}"
1010
style = [
1111
"ruff check {args:.}",

requirements-testing.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ pytest-timeout == 2.3.*
66
pytest-xdist == 3.6.*
77
black == 25.*
88
ruff == 0.11.*
9-
mypy == 1.11.*
9+
mypy == 1.15.*
1010
psutil == 7.0.*
1111
types-PyYAML ~= 6.0

src/openjd/adaptor_runtime/_background/model.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import dataclasses as dataclasses
44
import json as json
55
from enum import Enum as Enum
6-
from typing import Any, ClassVar, Dict, Generic, Iterable, Type, TypeVar, cast
6+
from enum import EnumMeta
7+
from typing import Any, ClassVar, Dict, Type, TypeVar, cast, Generic
78

89
from ..adaptors import AdaptorState
910

@@ -100,14 +101,12 @@ def map(self, o: Dict) -> _T:
100101

101102
value = o[field.name]
102103
if dataclasses.is_dataclass(field.type):
103-
value = DataclassMapper(field.type).map(value)
104-
elif issubclass(field.type, Enum):
105-
[value] = [
106-
enum
107-
# Need to cast here for mypy
108-
for enum in cast(Iterable[Enum], list(field.type))
109-
if enum.value == value
110-
]
104+
# The init function expects a type, so any dataclasses in cls
105+
# will be a type.
106+
value = DataclassMapper(cast(type, field.type)).map(value)
107+
elif isinstance(field.type, EnumMeta):
108+
value = field.type(value)
109+
111110
args[field.name] = value
112111

113112
return self._cls(**args)

src/openjd/adaptor_runtime/adaptors/configuration/_configuration_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323

2424
_ConfigType = TypeVar("_ConfigType", bound=Configuration)
2525
_AdaptorConfigType = TypeVar("_AdaptorConfigType", bound=AdaptorConfiguration)
26+
_AdaptorConfigClassType = Type[_AdaptorConfigType]
2627

2728

2829
def create_adaptor_configuration_manager(
29-
config_cls: Type[_AdaptorConfigType],
30+
config_cls: _AdaptorConfigClassType,
3031
adaptor_name: str,
3132
default_config_path: str,
3233
schema_path: str | List[str] | None = None,

src/openjd/adaptor_runtime/process/_logging_subprocess.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def terminate(self, grace_time_s: float = 60) -> None:
177177
self._process.kill()
178178
self._process.wait()
179179
else:
180+
signal_type: signal.Signals
180181
if OSName.is_windows(): # pragma: is-posix
181182
# We use `CREATE_NEW_PROCESS_GROUP` to create the process,
182183
# so pid here is also the process group id and SIGBREAK can be only sent to the process group.

test/openjd/adaptor_runtime/unit/background/test_model.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@
22

33
import dataclasses
44

5+
from enum import Enum
6+
57
import pytest
68

79
from openjd.adaptor_runtime._background.model import DataclassMapper
810

911

12+
class StrEnum(str, Enum):
13+
TEST = "test_str"
14+
TEST_UNI = "test_☃"
15+
16+
17+
class NormalEnum(Enum):
18+
ONE = 1
19+
20+
1021
# Define two dataclasses to use for tests
1122
@dataclasses.dataclass
1223
class Inner:
@@ -17,6 +28,9 @@ class Inner:
1728
class Outer:
1829
outer_key: str
1930
inner: Inner
31+
test_str: StrEnum
32+
test_str_unicode: StrEnum
33+
normal_enum: NormalEnum
2034

2135

2236
class TestDataclassMapper:
@@ -26,17 +40,29 @@ class TestDataclassMapper:
2640

2741
def test_maps_nested_dataclass(self):
2842
# GIVEN
29-
input = {"outer_key": "outer_value", "inner": {"key": "value"}}
43+
input = {
44+
"outer_key": "outer_value",
45+
"inner": {
46+
"key": "value",
47+
},
48+
"test_str": "test_str",
49+
"test_str_unicode": "test_☃",
50+
"normal_enum": 1,
51+
}
3052
mapper = DataclassMapper(Outer)
3153

3254
# WHEN
3355
result = mapper.map(input)
3456

3557
# THEN
36-
assert isinstance(result, Outer)
37-
assert isinstance(result.inner, Inner)
38-
assert result.outer_key == "outer_value"
39-
assert result.inner.key == "value"
58+
expected_dataclass = Outer(
59+
outer_key="outer_value",
60+
inner=Inner(key="value"),
61+
test_str=StrEnum.TEST,
62+
test_str_unicode=StrEnum.TEST_UNI,
63+
normal_enum=NormalEnum.ONE,
64+
)
65+
assert result == expected_dataclass
4066

4167
def test_raises_when_field_is_missing(self):
4268
# GIVEN

test/openjd/adaptor_runtime_client/integ/test_integration_client_interface.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def test_graceful_shutdown(self) -> None:
3535

3636
# To avoid a race condition, giving some extra time for the logging subprocess to start.
3737
_sleep(0.5 if OSName.is_posix() else 4)
38+
signal_type: signal.Signals
3839
if OSName.is_windows():
3940
signal_type = signal.CTRL_BREAK_EVENT # type: ignore[attr-defined]
4041
else:
@@ -77,6 +78,7 @@ def test_client_in_thread_does_not_do_graceful_shutdown(self) -> None:
7778

7879
# To avoid a race condition, giving some extra time for the logging subprocess to start.
7980
_sleep(0.5 if OSName.is_posix() else 4)
81+
signal_type: signal.Signals
8082
if OSName.is_windows():
8183
signal_type = signal.CTRL_BREAK_EVENT # type: ignore[attr-defined]
8284
else:

0 commit comments

Comments
 (0)