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

PLC0414 conflicts with re-exporting imports in py files #5698

Closed
twoertwein opened this issue Jul 11, 2023 · 5 comments
Closed

PLC0414 conflicts with re-exporting imports in py files #5698

twoertwein opened this issue Jul 11, 2023 · 5 comments

Comments

@twoertwein
Copy link

Pandas uses similar code in pandas/_typing.py

if TYPE_CHECKING:
    if sys.version_info >= (3, 10):
        from typing import TypeGuard
    else:
        from typing_extensions import TypeGuard
else:
    TypeGuard: Any = None

TypeGuard is not used inside this file (pyright detects this). A fix for pyright is to use the redundant as TypeGuard import but PLC0414 conflicts with that. Alternatives are: ignore the pyright error or create __all__ (but that would need to contain a lot of symbols).

xref #3734 pandas-dev/pandas#54085

@zanieb
Copy link
Member

zanieb commented Jul 11, 2023

Thanks for the clear issue!

PLC0414 is not enabled by default — perhaps you don't want to use it in Pandas if you need to export names with the redundant as ... or perhaps it'd make sense to disable it in that file?

What do you see as the ideal behavior for Ruff here?

@twoertwein
Copy link
Author

Thank you, ignoring this rule (for this one file/or all) is probably the best option.

As far as I remember, flake8's F401 (haven't used it since switching to ruff :) ) also treats explicit re-exports as used imports.

@zanieb
Copy link
Member

zanieb commented Jul 12, 2023

Yes F401 will be raised on from . import foo but not from . import foo as foo (some discussion on that right now at #5697)

Anything else you can see Ruff doing better here or should we close this?

@twoertwein
Copy link
Author

Can be closed.

Anything else you can see Ruff doing better here or should we close this?

(Consider removing this rule.) I will ignore this rule.

@charliermarsh
Copy link
Member

Yeah PLC0414 is a strange rule because explicit re-export is a respected mechanism to indicate publicity by many tools (Ruff, but also Pyright).

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

No branches or pull requests

3 participants