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

resources imported but unused #4250

Closed
IamRezaMousavi opened this issue May 5, 2023 · 17 comments
Closed

resources imported but unused #4250

IamRezaMousavi opened this issue May 5, 2023 · 17 comments
Labels
configuration Related to settings and configuration

Comments

@IamRezaMousavi
Copy link

resources.py must imported to use Qt resources in project
resources file will generated by:
pyrcc5 resources.qrc -o "./resources.py"

how can I tell ruff to ignore resources import error??

ruff output:
window.py:22:26: F401 [*] resources imported but unused

pyproject.toml:

[tool.ruff]
line-length = 100

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]
"resources.py" = ["E501"]
"colorbox.py" = ["E722"]
"test.py" = ["E402", "F401"]

ruff version:
ruff 0.0.264

@JonathanPlasse
Copy link
Contributor

Can you provide a minimal reproducible code example?

@JonathanPlasse
Copy link
Contributor

Would adding a noqa be fine for your use case?

@IamRezaMousavi
Copy link
Author

Can you provide a minimal reproducible code example?

minimal example code:
https://stackoverflow.com/a/36673994
or see
https://gist.github.com/seanwu1105/4e9362cadedec5353874ef8e28463c2d

@IamRezaMousavi
Copy link
Author

Would adding a noqa be fine for your use case?

No I want to see this error for other import code
but ignore all the resources.py imports

@JonathanPlasse
Copy link
Contributor

I guess a setting could be added to ignore F401 for a list of imports.

@IamRezaMousavi
Copy link
Author

I guess a setting could be added to ignore F401 for a list of imports.

How?

@JonathanPlasse
Copy link
Contributor

It needs to be implemented.

@JonathanPlasse
Copy link
Contributor

Do you import ressources in a lot of files?
If not the noqa could be added manually.

@IamRezaMousavi
Copy link
Author

Do you import ressources in a lot of files?
If not the noqa could be added manually.

Yes

@charliermarsh charliermarsh added the configuration Related to settings and configuration label May 6, 2023
@IamRezaMousavi
Copy link
Author

Can you explain how can I implement this?

@JonathanPlasse
Copy link
Contributor

I can implement it if you want.

@IamRezaMousavi
Copy link
Author

I can implement it if you want.

I want to help you and contributing in this project.
If you have no problem!

@IamRezaMousavi
Copy link
Author

IamRezaMousavi commented May 18, 2023

We can add dummy-import-rgx
What you think?

@charliermarsh
Copy link
Member

No I want to see this error for other import code
but ignore all the resources.py imports

To clarify, you can ignore the unused import only for that line with:

import resources  # noqa: F401

That will prevent an unused import error from appearing for that line, but won't prevent other imports from being marked as unused.

@IamRezaMousavi
Copy link
Author

That will prevent an unused import error from appearing for that line, but won't prevent other imports from being marked as unused.

Right, but what if I want import like this?
If I just want to ignore _Name:

from ImportFrom import OtherName, _Name

I can do like this but it's ugly:

from ImportFrom import OtherName
from ImportFrom import _Name # noqa: F401

(This is solved in #4691 )

@charliermarsh
Copy link
Member

I think the conventional way to format that would be:

from ImportFrom import (
    OtherName,
    _Name,  # noqa: F401
)

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

No branches or pull requests

3 participants