Skip to content

Commit 7038426

Browse files
committed
fix import issue _typeshed and improve test
1 parent 4ce008f commit 7038426

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

scaleway-core/scaleway_core/utils/resolve_one_of.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
from __future__ import annotations
22
from collections.abc import Callable
3-
from scaleway_core.profile.profile import ProfileDefaults
43
from dataclasses import dataclass
54
from typing import Any, Dict, Generic, List, Optional, TypeVar
6-
from _typeshed import SupportsKeysAndGetItem
5+
6+
from typing import TYPE_CHECKING
7+
8+
if TYPE_CHECKING:
9+
from _typeshed import SupportsKeysAndGetItem
10+
711

812
T = TypeVar("T")
913

@@ -19,6 +23,12 @@ class OneOfPossibility(Generic[T]):
1923
def resolve_one_of(
2024
possibilities: List[OneOfPossibility[Any]], is_required: bool = False
2125
) -> SupportsKeysAndGetItem[str, Any]:
26+
"""
27+
Resolves the ideal parameter and value amongst an optional list.
28+
Uses marshal_func if provided.
29+
"""
30+
31+
# Try to resolve using non-None value
2232
for possibility in possibilities:
2333
if possibility.value is not None:
2434
if possibility.marshal_func is not None:
@@ -32,15 +42,20 @@ def resolve_one_of(
3242
for possibility in possibilities:
3343
if possibility.default is not None:
3444
if possibility.marshal_func is not None:
35-
raise ValueError(
36-
f"{possibility.param} is missing a required value for marshal_func"
37-
)
45+
# When no actual value, call with None as value
46+
return {
47+
possibility.param: possibility.marshal_func(
48+
None, possibility.default
49+
)
50+
}
3851
return {possibility.param: possibility.default}
3952

53+
# If required but unresolved, raise an error
4054
if is_required:
4155
possibilities_keys = " or ".join(
4256
[possibility.param for possibility in possibilities]
4357
)
4458
raise ValueError(f"one of ${possibilities_keys} must be present")
4559

60+
# Else, return empty dict
4661
return {}

scaleway/tests/test_vpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class TestScalewayVPCV2(unittest.TestCase):
1414
@classmethod
1515
def setUpClass(self):
16-
self.client = Client.from_env()
16+
self.client = Client.from_config_file_and_env()
1717
self.vpcAPI = VpcV2API(self.client)
1818
self.project_id = self.client.default_project_id
1919
self.region = region

0 commit comments

Comments
 (0)