Skip to content

Conversation

@w0nder1ng
Copy link
Contributor

Summary

This change prevents the visit_* methods of ast.NodeVisitor/NodeTransformer and the do_* methods of http.server.BaseHTTPRequestHandler from triggering N802. See #9400 for more information.

In Lib/ast.py:

class NodeVisitor(object):
    def visit(self, node):
        """Visit a node."""
        method = 'visit_' + node.__class__.__name__
        visitor = getattr(self, method, self.generic_visit)
        return visitor(node)

Example usage

from ast import NodeVisitor

class Visitor(NodeVisitor):
    def visit_Constant(self, node):
        print(f"visited a constant with value {node.value}")

Previously, this would trigger a N802 violation, even though the uppercase name is the intended way of using those subclasses.

Test Plan

I added tests to pep8_naming/N802.py.

…http.server.BaseHTTPRequestHandler from triggering N802
@github-actions
Copy link
Contributor

github-actions bot commented Jun 24, 2025

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+3 -8 violations, +0 -0 fixes in 4 projects; 51 projects unchanged)

apache/airflow (+0 -6 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select ALL

- airflow-core/src/airflow/utils/scheduler_health.py:36:9: N802 Function name `do_GET` should be lowercase
- dev/breeze/src/airflow_breeze/commands/release_management_commands.py:3387:17: N802 Function name `visit_FunctionDef` should be lowercase
- scripts/ci/pre_commit/check_deferrable_default.py:45:9: N802 Function name `visit_FunctionDef` should be lowercase
- scripts/in_container/run_template_fields_check.py:52:9: N802 Function name `visit_FunctionDef` should be lowercase
- scripts/in_container/run_template_fields_check.py:57:9: N802 Function name `visit_Assign` should be lowercase
- scripts/in_container/run_template_fields_check.py:66:9: N802 Function name `visit_AnnAssign` should be lowercase

bokeh/bokeh (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select ALL

- tests/support/plugins/file_server.py:59:9: N802 Function name `do_GET` should be lowercase

langchain-ai/langchain (+2 -0 violations, +0 -0 fixes)

+ libs/cli/langchain_cli/namespaces/migrate/generate/utils.py:23:48: RUF100 [*] Unused `noqa` directive (unused: `N802`)
+ libs/cli/langchain_cli/namespaces/migrate/generate/utils.py:42:50: RUF100 [*] Unused `noqa` directive (unused: `N802`)

latchbio/latch (+1 -1 violations, +0 -0 fixes)

- src/latch_cli/auth/oauth2.py:89:17: N802 Function name `do_GET` should be lowercase
+ src/latch_cli/centromere/ast_parsing.py:32:58: RUF100 [*] Unused `noqa` directive (unused: `N802`)

Changes by rule (2 rules affected)

code total + violation - violation + fix - fix
N802 8 0 8 0 0
RUF100 3 3 0 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+3 -8 violations, +0 -0 fixes in 4 projects; 51 projects unchanged)

apache/airflow (+0 -6 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- airflow-core/src/airflow/utils/scheduler_health.py:36:9: N802 Function name `do_GET` should be lowercase
- dev/breeze/src/airflow_breeze/commands/release_management_commands.py:3387:17: N802 Function name `visit_FunctionDef` should be lowercase
- scripts/ci/pre_commit/check_deferrable_default.py:45:9: N802 Function name `visit_FunctionDef` should be lowercase
- scripts/in_container/run_template_fields_check.py:52:9: N802 Function name `visit_FunctionDef` should be lowercase
- scripts/in_container/run_template_fields_check.py:57:9: N802 Function name `visit_Assign` should be lowercase
- scripts/in_container/run_template_fields_check.py:66:9: N802 Function name `visit_AnnAssign` should be lowercase

bokeh/bokeh (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- tests/support/plugins/file_server.py:59:9: N802 Function name `do_GET` should be lowercase

langchain-ai/langchain (+2 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

+ libs/cli/langchain_cli/namespaces/migrate/generate/utils.py:23:48: RUF100 [*] Unused `noqa` directive (unused: `N802`)
+ libs/cli/langchain_cli/namespaces/migrate/generate/utils.py:42:50: RUF100 [*] Unused `noqa` directive (unused: `N802`)

latchbio/latch (+1 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

- src/latch_cli/auth/oauth2.py:89:17: N802 Function name `do_GET` should be lowercase
+ src/latch_cli/centromere/ast_parsing.py:32:58: RUF100 [*] Unused `noqa` directive (unused: `N802`)

Changes by rule (2 rules affected)

code total + violation - violation + fix - fix
N802 8 0 8 0 0
RUF100 3 3 0 0 0

@MichaReiser MichaReiser added the rule Implementing or modifying a lint rule label Jun 24, 2025
@MichaReiser
Copy link
Member

MichaReiser commented Jun 24, 2025

I don't think the special handling for NodeVisitor is necessary because typeshed defines all methods on NodeVisitor and, therefore, using @typing.override works (mypy)

Special casing the http handler seems fine, while unfortunate

@w0nder1ng
Copy link
Contributor Author

@typing.override was added in 3.12, so it's not available in 3.11 or earlier, which is where I ran into this issue. Could the NodeVisitor check be gated behind python version < 3.12?

@w0nder1ng
Copy link
Contributor Author

@MichaReiser is this an acceptable solution?

Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me if it's okay with @MichaReiser. I just had a few small suggestions.

Before 3.12 I think users could still get @override from typing_extensions, but I'm not sure if that would be a better approach.

@MichaReiser MichaReiser enabled auto-merge (squash) July 14, 2025 08:24
@MichaReiser MichaReiser merged commit 26f736b into astral-sh:main Jul 14, 2025
34 checks passed
dcreager added a commit that referenced this pull request Jul 14, 2025
* dcreager/merge-arguments: (223 commits)
  fix docs
  Combine CallArguments and CallArgumentTypes
  [ty] Sync vendored typeshed stubs (#19334)
  [`refurb`] Make example error out-of-the-box (`FURB122`) (#19297)
  [refurb] Make example error out-of-the-box (FURB177) (#19309)
  [ty] ignore errors when reformatting codemodded typeshed (#19332)
  [ty] Provide docstrings for stdlib APIs when hovering over them in an IDE (#19311)
  [ty] Add virtual files to the only project database (#19322)
  Add t-string fixtures for rules that do not need to be modified (#19146)
  [ty] Remove `FileLookupError` (#19323)
  [ty] Fix handling of metaclasses in `object.<CURSOR>` completions
  [ty] Use an interval map for scopes by expression (#19025)
  [ty] List all `enum` members (#19283)
  [ty] Handle configuration errors in LSP more gracefully (#19262)
  [ty] Use python version and path from Python extension (#19012)
  [`pep8_naming`] Avoid false positives on standard library functions with uppercase names (`N802`) (#18907)
  Update Rust crate toml to 0.9.0 (#19320)
  [ty] Fix server version (#19284)
  Update NPM Development dependencies (#19319)
  Update taiki-e/install-action action to v2.56.13 (#19317)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants