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

SWAP and MISSING flake8-annotations (ANN) #16854

Open
p1-dta opened this issue Mar 19, 2025 · 3 comments
Open

SWAP and MISSING flake8-annotations (ANN) #16854

p1-dta opened this issue Mar 19, 2025 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@p1-dta
Copy link

p1-dta commented Mar 19, 2025

Summary

ANN203 does not exist, ANN202 detect protected AND private when it should only detect protected, ANN202 documentation mention private instead of protected.

From flake8-annotations:

  • ANN202: Missing return type annotation for protected function
  • ANN203: Missing return type annotation for secret function

From Ruff Rules documentation:

From Playground:

  • ANN202 detect protected function but mention "private" function
  • ANN202 also detect private functions when it shouldn't
  • ANN203 not raised

Expected detection:

  • ANN202: Missing return type annotation for protected function
  • ANN203: Missing return type annotation for secret function
@ntBre ntBre added the question Asking for support or clarification label Mar 19, 2025
@ntBre
Copy link
Contributor

ntBre commented Mar 19, 2025

Thanks for opening the issue! Based on the PR adding support for flake8-annotations rules, I think this was an intentional choice to combine ANN202 and ANN203. I also think "private" is pretty reasonable for both types. I don't think I've run into the "protected" and "secret" terminology before.

Is this causing you any problems, or is it just a difference from the upstream rule?

@p1-dta
Copy link
Author

p1-dta commented Mar 19, 2025

Hi.
In a nutshell: Ok for me, this need to be documented but we can close if you want, thanks for answering.

If this is a ruff-specific implementation and design choice, I understand but this should be explicitly stated in documentation.

No issue for me except that it feels weird to go from 202 to 204 without 203 and it is not coherent with flake8-annotations, even if I'm not against "updates" when it makes sense. In this case, to have two rules for annotations, one for protected and one for private doesn't seems very valuable to me.

For protected, that's the one leading underscore attributes or methods that, by convention, should not be accessed from outside of class scope, but still shared to subclasses. You can find here two instances of the word "protected" used here and here.
For "secret", I don't know why they used this wording in the flake8 extension, maybe to explicitly emphasize the difference with conventional OOP private attr.

@ntBre
Copy link
Contributor

ntBre commented Mar 19, 2025

Ah, I see, thanks. I think we could definitely mention this in the documentation.

@ntBre ntBre added documentation Improvements or additions to documentation and removed question Asking for support or clarification labels Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants