Skip to content

logging module LogRecord __init__ mismatch #9913

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

Closed
aminalaee opened this issue Mar 21, 2023 · 2 comments · Fixed by #9914
Closed

logging module LogRecord __init__ mismatch #9913

aminalaee opened this issue Mar 21, 2023 · 2 comments · Fixed by #9914

Comments

@aminalaee
Copy link
Contributor

According to the Python docs for the LogRecord in logging module the msg argument and property is a string:
https://docs.python.org/3/library/logging.html#logging.LogRecord

In the typeshed, the attribute is set to a str:

But the msg input argument is set to object:

And looking at the source the argument is not changed at all:
https://github.com/python/cpython/blob/7f760c2fca3dc5f46a518f5b7622783039bc8b7b/Lib/logging/__init__.py#L305

Unless this is for a backwards-compatible version, I guess this is a mismatch.

@aminalaee aminalaee changed the title logging module LogRecord __init__ logging module LogRecord __init__ mismatch Mar 21, 2023
@Akuli
Copy link
Collaborator

Akuli commented Mar 22, 2023

I think we should just use str everywhere. If you are passing a non-string, and it isn't converted to a string anywhere in logging, it may fail when some completely unrelated code handles the log records elsewhere. IMO this is exactly what type checking is supposed to avoid.

@aminalaee
Copy link
Contributor Author

But in that case type checking is actually stricter than the implementation, and causes mismatch between typeshed and python docs and implementation.

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

Successfully merging a pull request may close this issue.

2 participants