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

Make conf.get with a check_type=bool raise exception if invalid value #16976

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions conans/model/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,10 @@ def get(self, conf_name, default=None, check_type=None, choices=None):
if choices is not None and v not in choices:
raise ConanException(f"Unknown value '{v}' for '{conf_name}'")
# Some smart conversions
if check_type is bool and not isinstance(v, bool):
# Perhaps, user has introduced a "false", "0" or even "off"
return str(v).lower() not in Conf.boolean_false_expressions
if check_type is bool and not (isinstance(v, bool) or str(v).lower() not in
Conf.boolean_false_expressions):
raise ConanException(f"[conf] {conf_name} must be a boolean-like object "
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
f"(false, 0, off, etc) and value '{v}' does not match it.")
elif check_type is str and not isinstance(v, str):
return str(v)
elif v is None: # value was unset
Expand Down