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

SLF001 and type annotations #9013

Closed
ofek opened this issue Dec 5, 2023 · 3 comments · Fixed by #9036
Closed

SLF001 and type annotations #9013

ofek opened this issue Dec 5, 2023 · 3 comments · Fixed by #9036
Assignees
Labels
question Asking for support or clarification

Comments

@ofek
Copy link
Contributor

ofek commented Dec 5, 2023

Should this trigger for type annotations?

from __future__ import annotations

import argparse
from typing import Any

def build_command(subparsers: argparse._SubParsersAction, defaults: Any) -> None:
    ...
@charliermarsh
Copy link
Member

That is an interesting question... My initial reaction was "Yes, it should trigger", since it still represents an access on a private API. But I can see why this would be necessary in the ordinary course of business (calling public methods that return opaque private types). So perhaps it should be allowed.

(I kind of feel like such objects should be public, with private interfaces as in, e.g., https://bugs.python.org/issue41592, but recognize that's not within the client's control.)

@charliermarsh charliermarsh added the question Asking for support or clarification label Dec 7, 2023
@ofek
Copy link
Contributor Author

ofek commented Dec 7, 2023

Yeah your assessment is exactly correct, public APIs often do not have perfect encapsulation and expose private details.

@charliermarsh charliermarsh self-assigned this Dec 7, 2023
charliermarsh added a commit that referenced this issue Dec 7, 2023
## Summary

Occasionally, valid code needs to use `argparse._SubParsersAction` in a
type annotation. This isn't great, but it's indicative of the fact that
public interfaces can return private types. If you accessed that private
type via a private interface, then we should be flagging the call site,
rather than the annotation.

Closes #9013.
@ofek
Copy link
Contributor Author

ofek commented Dec 7, 2023

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for support or clarification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants