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

import-private-name (PLC2701) does not respect @type_check_only #15294

Open
Avasam opened this issue Jan 6, 2025 · 1 comment
Open

import-private-name (PLC2701) does not respect @type_check_only #15294

Avasam opened this issue Jan 6, 2025 · 1 comment
Labels
needs-decision Awaiting a decision from a maintainer wish Not on the current roadmap; maybe in the future

Comments

@Avasam
Copy link
Contributor

Avasam commented Jan 6, 2025

import-private-name (PLC2701) says that

This rule ignores private name imports that are exclusively used in type annotations. Ideally, types would be public; however, this is not always possible when using third-party libraries.

However, it'll still trigger when the name is subclassed, but said class is decorated with typing.type_check_only in a stub file:
https://play.ruff.rs/658cc2b7-e7e0-4195-a19c-e1239a465e71

from _typeshed import SupportsWrite
from typing import Protocol, TypeVar, type_check_only
_T_contra = TypeVar("_T_contra", contravariant=True)

@type_check_only
class _Stream(SupportsWrite[_T_contra], Protocol):
    def seek(self, offset: int, whence: int = ..., /) -> int: ...
@MichaReiser
Copy link
Member

Ruff doesn't support the @type_check_only decorator yet. So a first step would be to add support for it and then go through all the rules that need changing.

@MichaReiser MichaReiser added wish Not on the current roadmap; maybe in the future needs-decision Awaiting a decision from a maintainer labels Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision Awaiting a decision from a maintainer wish Not on the current roadmap; maybe in the future
Projects
None yet
Development

No branches or pull requests

2 participants