Skip to content

Commit ba629fe

Browse files
authored
[pep8-naming] Fix N802 false positives for CGIHTTPRequestHandler and SimpleHTTPRequestHandler (#19432)
## Summary Fixes #19422
1 parent bb3a05f commit ba629fe

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

crates/ruff_linter/resources/test/fixtures/pep8_naming/N802.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,25 @@ def do_GET(self):
8484
def dont_GET(self):
8585
pass
8686

87+
88+
from http.server import CGIHTTPRequestHandler
89+
90+
91+
class MyCGIRequestHandler(CGIHTTPRequestHandler):
92+
def do_OPTIONS(self):
93+
pass
94+
95+
def dont_OPTIONS(self):
96+
pass
97+
98+
99+
from http.server import SimpleHTTPRequestHandler
100+
101+
102+
class MySimpleRequestHandler(SimpleHTTPRequestHandler):
103+
def do_OPTIONS(self):
104+
pass
105+
106+
def dont_OPTIONS(self):
107+
pass
108+

crates/ruff_linter/src/rules/pep8_naming/rules/invalid_function_name.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,21 @@ pub(crate) fn invalid_function_name(
100100
return;
101101
}
102102

103-
// Ignore the do_* methods of the http.server.BaseHTTPRequestHandler class
103+
// Ignore the do_* methods of the http.server.BaseHTTPRequestHandler class and its subclasses
104104
if name.starts_with("do_")
105105
&& parent_class.is_some_and(|class| {
106106
any_base_class(class, semantic, &mut |superclass| {
107107
let qualified = semantic.resolve_qualified_name(superclass);
108108
qualified.is_some_and(|name| {
109109
matches!(
110110
name.segments(),
111-
["http", "server", "BaseHTTPRequestHandler"]
111+
[
112+
"http",
113+
"server",
114+
"BaseHTTPRequestHandler"
115+
| "CGIHTTPRequestHandler"
116+
| "SimpleHTTPRequestHandler"
117+
]
112118
)
113119
})
114120
})

crates/ruff_linter/src/rules/pep8_naming/snapshots/ruff_linter__rules__pep8_naming__tests__N802_N802.py.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,21 @@ N802.py:84:9: N802 Function name `dont_GET` should be lowercase
5555
| ^^^^^^^^ N802
5656
85 | pass
5757
|
58+
59+
N802.py:95:9: N802 Function name `dont_OPTIONS` should be lowercase
60+
|
61+
93 | pass
62+
94 |
63+
95 | def dont_OPTIONS(self):
64+
| ^^^^^^^^^^^^ N802
65+
96 | pass
66+
|
67+
68+
N802.py:106:9: N802 Function name `dont_OPTIONS` should be lowercase
69+
|
70+
104 | pass
71+
105 |
72+
106 | def dont_OPTIONS(self):
73+
| ^^^^^^^^^^^^ N802
74+
107 | pass
75+
|

0 commit comments

Comments
 (0)