Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise error if check_type=int and conf value is set to bool #15378

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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