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

Inproper F401: "imported but unused" for sumodule if parent module is imported with an alias. #373

Closed
ghuls opened this issue Oct 9, 2022 · 5 comments · Fixed by #374
Closed
Assignees
Labels
bug Something isn't working

Comments

@ghuls
Copy link

ghuls commented Oct 9, 2022

Inproper F401: "imported but unused" for sumodule if parent module is imported with an alias.

import pyarrow as pa

import pyarrow.csv

print(pa.csv.read_csv("test.csv"))
$ ruff test_import.py 
No pyproject.toml found.
Falling back to default configuration...
Found 1 error(s).
test_import.py:3:1: F401 `pyarrow.csv` imported but unused
1 potentially fixable with the --fix option.
@charliermarsh charliermarsh added the bug Something isn't working label Oct 9, 2022
@charliermarsh
Copy link
Member

Good catch, will fix this.

@charliermarsh charliermarsh self-assigned this Oct 9, 2022
@charliermarsh
Copy link
Member

(Found the offending code, working on fix now.)

@ghuls
Copy link
Author

ghuls commented Oct 9, 2022

Thanks. It solves the problem.
Maybe it would be good to invalidate the ruff cache in the ruff binary is not the same between invocations as first I thought you pushed unrelated changes to master as the errors were the same after recompilation.

Found another one:

$ ruff test_import.py 
No pyproject.toml found.
Falling back to default configuration...
Found 1 error(s).
test_import.py:3:1: F401 `numpy` imported but unused
1 potentially fixable with the --fix option.

It might be more tricky to solve as in involves type annotations in quoted strings.

import sys

import numpy as np

if sys.version_info >= (3, 10):
    from typing import TypeAlias
else:
    from typing_extensions import TypeAlias


CustomInt: TypeAlias = "np.int8 | np.int16"

@charliermarsh
Copy link
Member

That one should work too, let me file a separate issue.

@charliermarsh
Copy link
Member

Maybe it would be good to invalidate the ruff cache in the ruff binary is not the same between invocations as first I thought you pushed unrelated changes to master as the errors were the same after recompilation.

Hmm yeah. We do put the Cargo version in the cache key, so it's invalidated between releases. But I can see how this would be confusing when running against Git etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants