Skip to content

Commit

Permalink
Raise error if check_type=int and conf value is set to bool (#15378)
Browse files Browse the repository at this point in the history
raise if bool on int check
  • Loading branch information
czoido authored Jan 3, 2024
1 parent 029b5b5 commit 30076dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion conans/model/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ def get(self, conf_name, default=None, check_type=None, choices=None):
return str(v)
elif v is None: # value was unset
return default
elif check_type is not None and not isinstance(v, check_type):
elif (check_type is not None and not isinstance(v, check_type) or
check_type is int and isinstance(v, bool)):
raise ConanException(f"[conf] {conf_name} must be a "
f"{check_type.__name__}-like object. The value '{v}' "
f"introduced is a {type(v).__name__} object")
Expand Down
5 changes: 5 additions & 0 deletions conans/test/unittests/model/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def test_conf_get_check_type_and_default():
zlib:user.company.check:shared_str="False"
zlib:user.company.check:static_str=off
user.company.list:newnames+=myname
core.download:parallel=True
""")
c = ConfDefinition()
c.loads(text)
Expand All @@ -238,6 +239,10 @@ def test_conf_get_check_type_and_default():
assert c.get("zlib:user.company.check:static_str") == "off"
assert c.get("zlib:user.company.check:static_str", check_type=bool) is False # smart conversion
assert c.get("user.company.list:newnames") == ["myname"] # Placeholder is removed
with pytest.raises(ConanException) as exc_info:
c.get("core.download:parallel", check_type=int)
assert ("[conf] core.download:parallel must be a int-like object. "
"The value 'True' introduced is a bool object") in str(exc_info.value)


def test_conf_pop():
Expand Down

0 comments on commit 30076dc

Please sign in to comment.