0

When I try to override the logging behaviour in my BaseHTTPRequestHandler-subclass like this:

from http.server import BaseHTTPRequestHandler

class MyHandler(BaseHTTPRequestHandler):

    def log_message(self, fmt, *args):
        pass

I get this warning

"Number of parameters was 3 in 'BaseHTTPRequestHandler.log_message' and is now 3 in overriding 'MyHandler.log_message' method Pylint(W0221:arguments-differ)"

This is strange because the number of arguments is obviously correct, as the message itself states. Is the varargs (*args) causing a problem with inheritance here?

1 Answer 1

1

The error message is misleading, but this is not a false positive. There is a problem with the code (and it has nothing to do with *varargs)

In stdlib\http\server.pyi of typeshed we find this signature for the super-method:

def log_message(self, format: str, *args: Any) -> None: ...

The argument name is format and not fmt. That is a problem because a caller of the method may pass the second argument as a keyword argument: server.log_message(format="something") and this code-snippet ought to work on a BaseHTTPRequestHandler as well as a MyHandler by the Liskov substitution principle.

The wrong argument name triggers Pylint(W0221:arguments-differ) even though the message and documentation hint only at the number of arguments.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.