Skip to content

Commit c41f7d2

Browse files
committed
fix: type issue
1 parent 90d61b3 commit c41f7d2

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed
Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,51 @@
1-
from collections.abc import Callable
21
from dataclasses import dataclass
32
from typing import Any, Dict, Generic, List, Optional, TypeVar
43

5-
from scaleway_core.profile import ProfileDefaults
6-
74
T = TypeVar("T")
85

96

107
@dataclass
118
class OneOfPossibility(Generic[T]):
129
param: str
10+
1311
value: Optional[T]
14-
default: Optional[T | ProfileDefaults] = None
15-
marshal_func: Optional[Callable[[T, ProfileDefaults | None], Dict[str, Any]]] = None
12+
13+
default: Optional[T] = None
1614

1715

1816
def resolve_one_of(
1917
possibilities: List[OneOfPossibility[Any]], is_required: bool = False
20-
) -> dict[str, Any | None] | str | dict[Any, Any]:
18+
) -> Dict[str, Any]:
2119
"""
2220
Resolves the ideal parameter and value amongst an optional list.
23-
Uses marshal_func if provided.
2421
"""
2522

26-
# Try to resolve using non-None value
23+
# Get the first non-empty parameter
2724
for possibility in possibilities:
2825
if possibility.value is not None:
29-
if possibility.marshal_func is not None:
30-
return {
31-
possibility.param: possibility.marshal_func(
32-
possibility.value, possibility.default
33-
)
34-
}
3526
return {possibility.param: possibility.value}
3627

37-
# Try to resolve using non-None default
28+
# Get the first non-empty default
3829
for possibility in possibilities:
3930
if possibility.default is not None:
31+
<<<<<<< HEAD
4032
if possibility.marshal_func is not None:
4133
# When no actual value, call with None as value
4234
return {
4335
possibility.param: possibility.marshal_func(
4436
None, possibility.default
4537
)
4638
}
39+
=======
40+
>>>>>>> 539c303 (Revert "fix(core): management one_of")
4741
return {possibility.param: possibility.default}
4842

49-
# If required but unresolved, raise an error
43+
# If required, raise an error
5044
if is_required:
5145
possibilities_keys = " or ".join(
5246
[possibility.param for possibility in possibilities]
5347
)
5448
raise ValueError(f"one of ${possibilities_keys} must be present")
5549

56-
# Else, return empty dict
50+
# Else, return an empty dict
5751
return {}

0 commit comments

Comments
 (0)