[pep8-naming] Fix N802 false positives for CGIHTTPRequestHandler and SimpleHTTPRequestHandler (#19432)

## Summary

Fixes #19422
This commit is contained in:
Dan Parizher 2025-07-23 12:04:11 -04:00 committed by GitHub
parent bb3a05f92b
commit ba629fe262
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 48 additions and 2 deletions

View file

@ -84,3 +84,25 @@ class MyRequestHandler(BaseHTTPRequestHandler):
def dont_GET(self): def dont_GET(self):
pass pass
from http.server import CGIHTTPRequestHandler
class MyCGIRequestHandler(CGIHTTPRequestHandler):
def do_OPTIONS(self):
pass
def dont_OPTIONS(self):
pass
from http.server import SimpleHTTPRequestHandler
class MySimpleRequestHandler(SimpleHTTPRequestHandler):
def do_OPTIONS(self):
pass
def dont_OPTIONS(self):
pass

View file

@ -100,7 +100,7 @@ pub(crate) fn invalid_function_name(
return; return;
} }
// Ignore the do_* methods of the http.server.BaseHTTPRequestHandler class // Ignore the do_* methods of the http.server.BaseHTTPRequestHandler class and its subclasses
if name.starts_with("do_") if name.starts_with("do_")
&& parent_class.is_some_and(|class| { && parent_class.is_some_and(|class| {
any_base_class(class, semantic, &mut |superclass| { any_base_class(class, semantic, &mut |superclass| {
@ -108,7 +108,13 @@ pub(crate) fn invalid_function_name(
qualified.is_some_and(|name| { qualified.is_some_and(|name| {
matches!( matches!(
name.segments(), name.segments(),
["http", "server", "BaseHTTPRequestHandler"] [
"http",
"server",
"BaseHTTPRequestHandler"
| "CGIHTTPRequestHandler"
| "SimpleHTTPRequestHandler"
]
) )
}) })
}) })

View file

@ -55,3 +55,21 @@ N802.py:84:9: N802 Function name `dont_GET` should be lowercase
| ^^^^^^^^ N802 | ^^^^^^^^ N802
85 | pass 85 | pass
| |
N802.py:95:9: N802 Function name `dont_OPTIONS` should be lowercase
|
93 | pass
94 |
95 | def dont_OPTIONS(self):
| ^^^^^^^^^^^^ N802
96 | pass
|
N802.py:106:9: N802 Function name `dont_OPTIONS` should be lowercase
|
104 | pass
105 |
106 | def dont_OPTIONS(self):
| ^^^^^^^^^^^^ N802
107 | pass
|