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

Heads up: Griffe's logger names are deprecated #218

Open
pawamoy opened this issue Jul 15, 2024 · 0 comments
Open

Heads up: Griffe's logger names are deprecated #218

pawamoy opened this issue Jul 15, 2024 · 0 comments

Comments

@pawamoy
Copy link

pawamoy commented Jul 15, 2024

Hello! Latest version of Griffe, 0.48, deprecated its logger names. Since it's not possible to detect usage of logger names, we can't emit deprecation warnings, so here am I giving you a heads up 🙂

I see that you're getting the logger of the Google docstring parser module. Next version of Griffe, v1, will use a single name for all loggers (so, a global logger): "griffe".

But I suspect you don't want to disable all Griffe warning logs, and rather just the ones emitted when parsing docstrings. For this, v1 will let you import the Griffe logger and disable it temporarily:

import griffe

with griffe.logger.disable():
    sections = griffe.parse_google(griffe.Docstring(o.__doc__))

Since we can't allow a deprecation period where both uses are valid, here is a workaround while waiting for v1:

import logging
from contextlib import contextmanager

@contextmanager
def disable_logging(self, name: str) -> Iterator[None]:
    """Temporarily disable logging."""
    logger = logging.getLogger(name)
    old_level = logger.level
    logger.setLevel(100)
    try:
        yield
    finally:
        logger.setLevel(old_level)

This way, you don't use the deprecated logger name, and when upgrading to v1 it will still work. Then you can finally use griffe.logger.disable.

If anything is unclear, let me know!

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