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

Update typing for level during setup #77

Merged
merged 1 commit into from
Nov 2, 2023
Merged

Conversation

userlerueda
Copy link
Contributor

When setting up daiquiri, daiquiri will work perfectly fine if you provide a valid string for log_level, e.g. "DEBUG", just as in the following example code:

import daiquiri

daiquiri.setup(level="DEBUG")

However, typing tools such as mypy or pylance will complain, because the typing defined is that it must conform to the level being an int.

Looking at the nested code, for logging, when setting the level it does the following check:

_nameToLevel = {
    'CRITICAL': CRITICAL,
    'FATAL': FATAL,
    'ERROR': ERROR,
    'WARN': WARNING,
    'WARNING': WARNING,
    'INFO': INFO,
    'DEBUG': DEBUG,
    'NOTSET': NOTSET,
}

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

So in essence it does check that it is an int or a string that is a key in the dictionary _nameToLevel.

Proposing that we update the typing so that typing checking tools do not complain.

@userlerueda userlerueda marked this pull request as ready for review November 1, 2023 21:38
@mergify mergify bot merged commit 8382335 into Mergifyio:main Nov 2, 2023
9 checks passed
@userlerueda userlerueda deleted the patch-1 branch November 21, 2023 03:09
@userlerueda
Copy link
Contributor Author

Hi @jd it seems like although 3.2.4 is released, it is not showing up in PyPi, do you know why that is?

@jd
Copy link
Member

jd commented Jan 25, 2024

Fixed

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

Successfully merging this pull request may close these issues.

2 participants