-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
false positive 'useless-import-alias' error for mypy-compatible explicit re-exports #6006
Comments
I think |
I don't think there is a way for pylint to detect if the reexport is intended or not. Maybe we could ignore Probably the easiest solution in your case would be to add a module level |
Yeah, other linters like mypy specifically support
|
Yeah I remember when I used liclipse (eclipse + pydev) this was a pain. This is an issue with the IDE though, Pycharm Community Edition handle this correctly. |
Sure, some IDEs can help with typos in |
As @cdce8p said, the solution is to disable. I think this is going to stay that way because I don't see how pylint can guess the intent of the implementer. We could make this check optional but I think if you're making library API using this you're more able to disable the check than a beginner making a genuine mistake is to activate it. We're going to document this in the |
Ok, thanks for that. As usage of mypy and mypy-style explicit re-imports continues to grow, it would be interesting to know how many pylint users end up having to disable |
An alternative solution would be to not raise this message in
To be frank, it's mostly opened issues and the thumbs-up / comments those issues gather. I'm not looking specifically at open sources projects for each messages it's really time consuming. A well researched comments on this issue with stats and sources, a proposition that is easily implementable with a better result than what we have currently, or this issue gathering 50+ thumbs up and a lot of attention would definitely make us reconsider. |
Got it, good to know. |
Just noticed https://github.com/microsoft/pyright/releases/tag/1.1.278
One more tool (pyright) flipping in this direction, fwiw. |
We'll need an option to exclude |
Bug description
Suppose a package has the following layout:
Since the submodules here implement public APIs,
__init__.py
imports and re-exports them, expecting users to import them from the public, top-level package, e.g.from package import Api1
.Since the implementations of
Api1
andApi2
are complex, they are split into_submodule1.py
and_submodule2.py
for better maintainability and separation of concerns.So
__init__.py
looks like this:The reason for the
as
aliases here is to be explicit that these imports are for the purpose of re-export (without having to resort to defining__all__
, which is error-prone). Without theas
aliases, popular linters such asmypy
will raise an "implicit re-export" error (docs -- part ofmypy --strict
).However, pylint does not currently understand this usage, and raises "useless-import-alias" errors.
Example real-world code triggering pylint false positive errors: https://github.com/jab/bidict/blob/caf703e959ed4471bc391a7794411864c1d6ab9d/bidict/__init__.py#L61-L78
Configuration
No response
Command used
Pylint output
Expected behavior
No "useless-import-alias" errors should be flagged.
Pylint version
OS / Environment
No response
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: