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

log_level type should be Union[str, int] and not just str #66

Open
gioruffa opened this issue Aug 25, 2022 · 0 comments
Open

log_level type should be Union[str, int] and not just str #66

gioruffa opened this issue Aug 25, 2022 · 0 comments

Comments

@gioruffa
Copy link

Hello there,
First of all: thanks a lot for the great library. It has sensibly improved our life when writing custom resources.

I have found a small inconsistency in the type hints for the CfnResource's log_level constructor parameter.

Current behavior

Version affected: main branch f2095c5

CfnResource constructor specifies that log_level should be a string.
In practice though, the log_level is used in log_helper.py to set the log level on the root logger in the stdlib logging module.

    logging.root.setLevel(level)

The logging module supports both string and integers to specify the log level. As a matter of fact, the log level is stored internally as an integer. The string is translated to an int using the _checkLevel method:

def _checkLevel(level):
    if isinstance(level, int):
        rv = level
    elif str(level) == level:
        if level not in _nameToLevel:
            raise ValueError("Unknown level: %r" % level)
        rv = _nameToLevel[level]
    else:
        raise TypeError("Level not an integer or a valid string: %r" % level)
    return rv

Expected behavior

log_level type hint should support both string and int.

Contribution

I am more than happy to create a PR to fix this, provided that you think it should be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant