Skip to content

logging module LogRecord __init__ mismatch #9913

Closed

Description

@aminalaee

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.

Activity

  1. changed the title [-]logging module LogRecord `__init__`[/-] [+]logging module LogRecord `__init__` mismatch[/+] on Mar 21, 2023
  2. Akuli commented on Mar 22, 2023

    @Akuli
    Collaborator

    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.

  3. aminalaee commented on Mar 23, 2023

    @aminalaee
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions