10BC0 rcsetup.validate_bool_maybe_none(None) raises Exception · Issue #2543 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

rcsetup.validate_bool_maybe_none(None) raises Exception #2543

@jankatins

Description

@jankatins

rcsetup.validate_bool_maybe_none(None) raise a ValueError. This is relevant when you deepcopy a rcParam structure or add all key,values of an old rcParam to a new rcParam. This problem showed up in the theme development of ggplot.

The function could be changed to:

def validate_bool_maybe_none(b):
    'Convert b to a boolean or raise'
    if type(b) is str:
        b = b.lower()
    if b is None or b == 'none':
        return None
    if b in ('t', 'y', 'yes', 'on', 'true', '1', 1, True):
        return True
    elif b in ('f', 'n', 'no', 'off', 'false', '0', 0, False):
        return False
    else:
        raise ValueError('Could not convert "%s" to boolean' % b)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0