fix new linter issues

This commit is contained in:
Jörg Thalheim
2024-07-08 16:30:15 +02:00
parent 83371fca47
commit e1b7805aef
2 changed files with 10 additions and 10 deletions

View File

@@ -81,11 +81,11 @@ def cast(value: Any, input_type: Any, opt_description: str) -> Any:
else: else:
raise ClanError(f"Invalid value {value} for boolean") raise ClanError(f"Invalid value {value} for boolean")
# handle lists # handle lists
elif get_origin(input_type) == list: elif get_origin(input_type) is list:
subtype = input_type.__args__[0] subtype = input_type.__args__[0]
return [cast([x], subtype, opt_description) for x in value] return [cast([x], subtype, opt_description) for x in value]
# handle dicts # handle dicts
elif get_origin(input_type) == dict: elif get_origin(input_type) is dict:
if not isinstance(value, dict): if not isinstance(value, dict):
raise ClanError( raise ClanError(
f"Cannot set {opt_description} directly. Specify a suboption like {opt_description}.<name>" f"Cannot set {opt_description} directly. Specify a suboption like {opt_description}.<name>"

View File

@@ -108,7 +108,7 @@ def test_type_from_schema_path_simple() -> None:
schema = dict( schema = dict(
type="boolean", type="boolean",
) )
assert parsing.type_from_schema_path(schema, []) == bool assert parsing.type_from_schema_path(schema, []) is bool
def test_type_from_schema_path_nested() -> None: def test_type_from_schema_path_nested() -> None:
@@ -125,8 +125,8 @@ def test_type_from_schema_path_nested() -> None:
age=dict(type="integer"), age=dict(type="integer"),
), ),
) )
assert parsing.type_from_schema_path(schema, ["age"]) == int assert parsing.type_from_schema_path(schema, ["age"]) is int
assert parsing.type_from_schema_path(schema, ["name", "first"]) == str assert parsing.type_from_schema_path(schema, ["name", "first"]) is str
def test_type_from_schema_path_dynamic_attrs() -> None: def test_type_from_schema_path_dynamic_attrs() -> None:
@@ -140,16 +140,16 @@ def test_type_from_schema_path_dynamic_attrs() -> None:
), ),
), ),
) )
assert parsing.type_from_schema_path(schema, ["age"]) == int assert parsing.type_from_schema_path(schema, ["age"]) is int
assert parsing.type_from_schema_path(schema, ["users", "foo"]) == str assert parsing.type_from_schema_path(schema, ["users", "foo"]) is str
def test_map_type() -> None: def test_map_type() -> None:
with pytest.raises(ClanError): with pytest.raises(ClanError):
config.map_type("foo") config.map_type("foo")
assert config.map_type("string") == str assert config.map_type("string") is str
assert config.map_type("integer") == int assert config.map_type("integer") is int
assert config.map_type("boolean") == bool assert config.map_type("boolean") is bool
assert config.map_type("attribute set of string") == dict[str, str] assert config.map_type("attribute set of string") == dict[str, str]
assert config.map_type("attribute set of integer") == dict[str, int] assert config.map_type("attribute set of integer") == dict[str, int]
assert config.map_type("null or string") == str | None assert config.map_type("null or string") == str | None