From 24218050331cce7fa3bc75ae8938228fdf8ca1c4 Mon Sep 17 00:00:00 2001 From: Jonathan Plasse <13716151+JonathanPlasse@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:32:40 +0200 Subject: [PATCH] Avoid N802 violations for @overload methods (#7498) Close #7479 The `@override` was already implemented ## Test Plan Tested the code in the issue. After removing all the noqa's, only one occurrence of `BadName()` raised a violation. Added a fixture --- crates/ruff/resources/test/fixtures/pep8_naming/N802.py | 6 +++++- .../src/rules/pep8_naming/rules/invalid_function_name.rs | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/ruff/resources/test/fixtures/pep8_naming/N802.py b/crates/ruff/resources/test/fixtures/pep8_naming/N802.py index ea7f979488..fca3520737 100644 --- a/crates/ruff/resources/test/fixtures/pep8_naming/N802.py +++ b/crates/ruff/resources/test/fixtures/pep8_naming/N802.py @@ -41,9 +41,13 @@ class Test(unittest.TestCase): assert True -from typing import override +from typing import override, overload @override def BAD_FUNC(): pass + +@overload +def BAD_FUNC(): + pass diff --git a/crates/ruff/src/rules/pep8_naming/rules/invalid_function_name.rs b/crates/ruff/src/rules/pep8_naming/rules/invalid_function_name.rs index a95ec1d084..468b29dc7a 100644 --- a/crates/ruff/src/rules/pep8_naming/rules/invalid_function_name.rs +++ b/crates/ruff/src/rules/pep8_naming/rules/invalid_function_name.rs @@ -70,9 +70,12 @@ pub(crate) fn invalid_function_name( return None; } - // Ignore any functions that are explicitly `@override`. These are defined elsewhere, - // so if they're first-party, we'll flag them at the definition site. - if visibility::is_override(decorator_list, semantic) { + // Ignore any functions that are explicitly `@override` or `@overload`. + // These are defined elsewhere, so if they're first-party, + // we'll flag them at the definition site. + if visibility::is_override(decorator_list, semantic) + || visibility::is_overload(decorator_list, semantic) + { return None; }