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

Add an exception for N802 for BaseHTTPRequestHandler subclasses' methods #9400

Open
ZeeD opened this issue Jan 5, 2024 · 2 comments
Open

Comments

@ZeeD
Copy link

ZeeD commented Jan 5, 2024

According to the doc you should use BaseHTTPRequestHandler subclassing it and implementing various do_SPAM methods, one for each request method.
But if in this basic snippet

from http.server import BaseHTTPRequestHandler
class MyRequestHandler(BaseHTTPRequestHandler):
    def do_GET(self) -> None: ...

ruff raises the error

N802 Function name `do_GET` should be lowercase

I would suggest to add an exception for the various do_XXX methods of the subclasses of BaseHTTPRequestHandler

@charliermarsh
Copy link
Member

One thing you can do to help Ruff here is add the @typing.override or @typing_extensions.override decorator to your method to indicate to tools that it's overriding an existing method.

@ZeeD
Copy link
Author

ZeeD commented Jan 5, 2024

Hi, thanks for the reply.
In this case I don't think it will work, as BaseHTTPRequestHandler does not implement such methods.
Instead they are part of an (informal) protocol, and retrieved dynamically via getattr - as you can see from https://github.com/python/cpython/blob/e56c53334f1adf5b4ea940036c76d18e80fe809d/Lib/http/server.py#L417-L424

BTW: if I add @typing.override I may trick ruff, but now mypy raises an error (because there is no do_SPAM method to override in BaseHTTPRequestHandler)

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