Skip to content

mypy does not catch string formatting errors in logging.log that are listed - not interpolated #18794

Open
@jvanasco

Description

@jvanasco

I could not find the same issue previously reported here, but these concepts are so generic I would not be surprised user-error is the cause of my failed earch.

Bug Report

In the following script, mypy correctly identifies a string formatting error in case B, which uses print

Cases E and F will both raise exceptions and are not caught.

To Reproduce

import logging
log = logging.getLogger(__name__)

a = "1"
b = "2"

print("print.passes A (%s) %s" % (a, b))
try:
    print("print.fail B [mypy catches] (%s) %s" % (a, ))
except TypeError:
    pass

log.critical("log.passes C (%s) %s" % (a, b))
log.critical("log.passes D (%s) %s" , a, b)
log.critical("log.fail E (%s) %s" , (a, b))
log.critical("log.fail F (%s) %s" , a)

Expected Behavior

I expected mypy to catch the string formatting error here.

I understand logging.log works differently and delays the interpolation. it would be nice if mypy could catch the number of arguments passed to logging to hint at a possible error or pass

Actual Behavior

mypy does not catch this

Your Environment

mypy-1.15.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions