From ede0fa675c33862e5bb4ef170c8b58fd9d76bf5f Mon Sep 17 00:00:00 2001 From: Matteo Voges Date: Thu, 21 Sep 2023 13:06:13 +0200 Subject: [PATCH] tests: apply mypy linting (E721) --- omegaconf/base.py | 2 +- .../built_in_resolvers/test_oc_deprecated.py | 2 +- tests/interpolation/test_custom_resolvers.py | 4 ++-- tests/interpolation/test_interpolation.py | 2 +- tests/structured_conf/test_structured_config.py | 10 +++++----- tests/test_basic_ops_dict.py | 6 +++--- tests/test_basic_ops_list.py | 4 ++-- tests/test_compare_dictconfig_vs_dict.py | 4 ++-- tests/test_utils.py | 8 ++++---- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/omegaconf/base.py b/omegaconf/base.py index 77e951058..4f1722650 100644 --- a/omegaconf/base.py +++ b/omegaconf/base.py @@ -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 diff --git a/tests/interpolation/built_in_resolvers/test_oc_deprecated.py b/tests/interpolation/built_in_resolvers/test_oc_deprecated.py index 7f03ab34a..983b4c719 100644 --- a/tests/interpolation/built_in_resolvers/test_oc_deprecated.py +++ b/tests/interpolation/built_in_resolvers/test_oc_deprecated.py @@ -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( diff --git a/tests/interpolation/test_custom_resolvers.py b/tests/interpolation/test_custom_resolvers.py index e645d0ace..c958199dd 100644 --- a/tests/interpolation/test_custom_resolvers.py +++ b/tests/interpolation/test_custom_resolvers.py @@ -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 @@ -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 diff --git a/tests/interpolation/test_interpolation.py b/tests/interpolation/test_interpolation.py index aa9536e2e..9e19adaef 100644 --- a/tests/interpolation/test_interpolation.py +++ b/tests/interpolation/test_interpolation.py @@ -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: diff --git a/tests/structured_conf/test_structured_config.py b/tests/structured_conf/test_structured_config.py index 67ac2189f..c957217ac 100644 --- a/tests/structured_conf/test_structured_config.py +++ b/tests/structured_conf/test_structured_config.py @@ -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", @@ -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) diff --git a/tests/test_basic_ops_dict.py b/tests/test_basic_ops_dict.py index bfc38d6d5..08c27d14a 100644 --- a/tests/test_basic_ops_dict.py +++ b/tests/test_basic_ops_dict.py @@ -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) @@ -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: diff --git a/tests/test_basic_ops_list.py b/tests/test_basic_ops_list.py index 0ff4f5f9e..538d3e0f4 100644 --- a/tests/test_basic_ops_list.py +++ b/tests/test_basic_ops_list.py @@ -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( @@ -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 diff --git a/tests/test_compare_dictconfig_vs_dict.py b/tests/test_compare_dictconfig_vs_dict.py index c868c4c16..0a1a5c81d 100644 --- a/tests/test_compare_dictconfig_vs_dict.py +++ b/tests/test_compare_dictconfig_vs_dict.py @@ -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 diff --git a/tests/test_utils.py b/tests/test_utils.py index 3be66d96e..9461ac9ad 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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: @@ -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 @@ -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: @@ -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: