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

PLR0904: false positive when using overload #14727

Closed
Matt-Ord opened this issue Dec 2, 2024 · 2 comments · Fixed by #14730
Closed

PLR0904: false positive when using overload #14727

Matt-Ord opened this issue Dec 2, 2024 · 2 comments · Fixed by #14730
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Matt-Ord
Copy link
Contributor

Matt-Ord commented Dec 2, 2024

This triggers PLR0904


class Test:
    @overload
    def test_method(self, a: Literal[1]) -> None: ...
    @overload
    def test_method(self, a: Literal[2]) -> None: ...
    @overload
    def test_method(self, a: Literal[3]) -> None: ...
    @overload
    def test_method(self, a: Literal[4]) -> None: ...
    @overload
    def test_method(self, a: Literal[5]) -> None: ...
    @overload
    def test_method(self, a: Literal[6]) -> None: ...
    @overload
    def test_method(self, a: Literal[7]) -> None: ...
    @overload
    def test_method(self, a: Literal[8]) -> None: ...
    @overload
    def test_method(self, a: Literal[9]) -> None: ...
    @overload
    def test_method(self, a: Literal[10]) -> None: ...
    @overload
    def test_method(self, a: Literal[11]) -> None: ...
    @overload
    def test_method(self, a: Literal[12]) -> None: ...
    @overload
    def test_method(self, a: Literal[13]) -> None: ...
    @overload
    def test_method(self, a: Literal[14]) -> None: ...
    @overload
    def test_method(self, a: Literal[15]) -> None: ...
    @overload
    def test_method(self, a: Literal[16]) -> None: ...
    @overload
    def test_method(self, a: Literal[17]) -> None: ...
    @overload
    def test_method(self, a: Literal[18]) -> None: ...
    @overload
    def test_method(self, a: Literal[19]) -> None: ...
    @overload
    def test_method(self, a: Literal[20]) -> None: ...
    @overload
    def test_method(self, a: Literal[21]) -> None: ...
    def test_method(self, a: Any) -> None: ...

This rule should ignore overload impls

Using ruff 0.8.1

@MichaReiser MichaReiser added bug Something isn't working good first issue Good for newcomers labels Dec 2, 2024
@MichaReiser
Copy link
Member

That makes sense to me. Thank you.

Rule code:

pub(crate) fn too_many_public_methods(
checker: &mut Checker,
class_def: &ast::StmtClassDef,
max_methods: usize,
) {

Code to test if a function is annotated with @overload

https://github.com/charliermarsh/ruff/blob/a73bebcf15e078c90cd590f0a8eb53313bbd5ea9/crates/ruff_python_semantic/src/analyze/visibility.rs#L30-L34

@Matt-Ord
Copy link
Contributor Author

Matt-Ord commented Dec 2, 2024

I'll have a go at fixing it

charliermarsh added a commit that referenced this issue Dec 2, 2024
Fixes #14727

## Summary

Fixes #14727

## Test Plan

cargo test

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants