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

logger.warning no longer supports UserWarning #477

Closed
justinessert opened this issue Nov 22, 2022 · 2 comments
Closed

logger.warning no longer supports UserWarning #477

justinessert opened this issue Nov 22, 2022 · 2 comments

Comments

@justinessert
Copy link

Context

It seems like with the latest version of the structlog package, we can no longer pass a UserWarning to logger.warning().

Behavior in 22.1.0 / Expected

Running this would result in the following log 2022-11-22 13:39.48 [warning ] test, as expected.

import structlog
logger = structlog.get_logger(__name__)
logger.warning(UserWarning("test"))

Behavior in 22.2.0 / Error

Running the same code will result in the following error.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/user/miniconda3/envs/env_name/lib/python3.9/site-packages/structlog/_log_levels.py", line 156, in meth
    return self._proxy_to_logger(name, event % args, **kw)
TypeError: unsupported operand type(s) for %: 'UserWarning' and 'tuple'

Workaround

This will replicate the behavior of 22.1, you can wrap the warning in a string, but it would be nice to have this supported as it was.

import structlog
logger = structlog.get_logger(__name__)
logger.warning(str(UserWarning("test")))
@hynek
Copy link
Owner

hynek commented Nov 22, 2022

This should be effectively fixed by #475 but I really wonder why you would do that?

@hynek
Copy link
Owner

hynek commented Nov 24, 2022

22.3 is on PyPI

@hynek hynek closed this as completed Nov 24, 2022
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

2 participants