Skip to content

Commit

Permalink
tests: apply mypy linting (E721)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoVoges committed Sep 21, 2023
1 parent 91a2d7c commit ede0fa6
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion omegaconf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def _validate_and_convert_interpolation_result(
# If the converted value is of the same type, it means that no conversion
# was actually needed. As a result, we can keep the original `resolved`
# (and otherwise, the converted value must be wrapped into a new node).
if type(conv_value) != type(res_value):
if type(conv_value) is not type(res_value):
must_wrap = True
resolved = conv_value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_deprecated(
with warns(UserWarning, match=re.escape(expected_warning)):
value = OmegaConf.select(cfg, key)
assert value == expected_value
assert type(value) == type(expected_value)
assert type(value) is type(expected_value)


@mark.parametrize(
Expand Down
4 changes: 2 additions & 2 deletions tests/interpolation/test_custom_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_register_resolver_1(restore_resolvers: Any) -> None:
{"k": "${plus_10:990}", "node": {"bar": 10, "foo": "${plus_10:${.bar}}"}}
)

assert type(c.k) == int
assert isinstance(c.k, int)
assert c.k == 1000
assert c.node.foo == 20 # this also tests relative interpolations with resolvers

Expand All @@ -116,7 +116,7 @@ def test_register_resolver_1_legacy(restore_resolvers: Any) -> None:
OmegaConf.legacy_register_resolver("plus_10", lambda x: int(x) + 10)
c = OmegaConf.create({"k": "${plus_10:990}"})

assert type(c.k) == int
assert isinstance(c.k, int)
assert c.k == 1000


Expand Down
2 changes: 1 addition & 1 deletion tests/interpolation/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_indirect_interpolation2() -> None:
def test_type_inherit_type(cfg: Any) -> None:
cfg = _ensure_container(cfg)
assert isinstance(cfg.a, type(cfg.b))
assert type(cfg.s) == str # check that string interpolations are always strings
assert isinstance(cfg.s, str) # check that string interpolations are always strings


def test_interpolation_in_list_key_error() -> None:
Expand Down
10 changes: 5 additions & 5 deletions tests/structured_conf/test_structured_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,10 @@ def test_interpolation(self, module: Any) -> Any:
assert conf.x == input_.x
assert conf.z1 == conf.x
assert conf.z2 == f"{conf.x}_{conf.y}"
assert type(conf.x) == int
assert type(conf.y) == int
assert type(conf.z1) == int
assert type(conf.z2) == str
assert isinstance(conf.x, int)
assert isinstance(conf.y, int)
assert isinstance(conf.z1, int)
assert isinstance(conf.z2, str)

@mark.parametrize(
"tested_type",
Expand Down Expand Up @@ -2010,7 +2010,7 @@ def test_union_instantiation(
if vk is _utils.ValueKind.VALUE:
assert cfg[key] == expected_val
if _utils.is_primitive_type_annotation(type(expected_val)):
assert type(cfg[key]) == type(expected_val)
assert type(cfg[key]) is type(expected_val)
else:
assert isinstance(cfg[key], Container)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_basic_ops_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ def test_items(cfg: Any, expected: Any, expected_no_resolve: Any) -> None:
pairs = list(cfg.items_ex(resolve=False))
assert pairs == expected_no_resolve
for idx in range(len(expected_no_resolve)):
assert type(pairs[idx][0]) == type(expected_no_resolve[idx][0]) # noqa
assert type(pairs[idx][1]) == type(expected_no_resolve[idx][1]) # noqa
assert type(pairs[idx][0]) is type(expected_no_resolve[idx][0])
assert type(pairs[idx][1]) is type(expected_no_resolve[idx][1])
else:
with expected_no_resolve:
cfg.items_ex(resolve=False)
Expand Down Expand Up @@ -515,7 +515,7 @@ def test_dict_pop(cfg: Dict[Any, Any], key: Any, default_: Any, expected: Any) -
val = c.pop(key)

assert val == expected
assert type(val) == type(expected)
assert type(val) is type(expected)


def test_dict_struct_mode_pop() -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_basic_ops_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def test_append_convert(lc: ListConfig, element: Any, expected: Any) -> None:
lc.append(element)
value = lc[-1]
assert value == expected
assert type(value) == type(expected)
assert type(value) is type(expected)


@mark.parametrize(
Expand Down Expand Up @@ -977,7 +977,7 @@ def test_setitem_slice(
assert cfg == expected
else:
expected_exception: Any = expected.expected_exception
if type(constructor) == type(list) and issubclass(
if type(constructor) == type(list) and issubclass( # noqa E721
expected_exception, UnsupportedValueType
):
return # standard list() can accept object() so skip
Expand Down
4 changes: 2 additions & 2 deletions tests/test_compare_dictconfig_vs_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ def key_coerced(self, key: Any, cfg_key_type: Any) -> Any:
See https://github.com/omry/omegaconf/pull/484#issuecomment-765772019
"""
assert issubclass(cfg_key_type, Enum)
if type(key) == str and key in [e.name for e in cfg_key_type]:
if type(key) is str and key in [e.name for e in cfg_key_type]:
return cfg_key_type[key]
elif type(key) == int and key in [e.value for e in cfg_key_type]:
elif type(key) is int and key in [e.value for e in cfg_key_type]:
return cfg_key_type(key)
else:
return key
Expand Down
8 changes: 4 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_node_wrap(
key=None,
)
assert ret._metadata.ref_type == ref_type
assert type(ret) == expected_type
assert isinstance(ret, expected_type)
assert ret == value

if is_optional:
Expand All @@ -100,7 +100,7 @@ def test_node_wrap(
parent=None,
key=None,
)
assert type(ret) == expected_type
assert isinstance(ret, expected_type)
# noinspection PyComparisonWithNone
assert ret == None # noqa E711

Expand Down Expand Up @@ -235,7 +235,7 @@ def test_node_wrap2(target_type: Any, value: Any, expected: Any) -> None:
res = _node_wrap(
ref_type=target_type, key="foo", value=value, is_optional=False, parent=None
)
assert type(res) == type(expected)
assert type(res) is type(expected)
assert res == expected
assert res._key() == "foo"
else:
Expand Down Expand Up @@ -1048,7 +1048,7 @@ def test_get_value_container(content: Any) -> None:
def test_get_value_of_node_subclass(node: Node, expected: Any) -> None:
result = _get_value(node)
assert result == expected
assert type(result) == type(expected)
assert type(result) is type(expected)


def test_ensure_container_raises_ValueError() -> None:
Expand Down

0 comments on commit ede0fa6

Please sign in to comment.