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

"rye lint --fix" fails #1414

Open
pcarinhas opened this issue Oct 13, 2024 · 3 comments
Open

"rye lint --fix" fails #1414

pcarinhas opened this issue Oct 13, 2024 · 3 comments

Comments

@pcarinhas
Copy link

Steps to Reproduce

  1. Install new rye : in this case 0.41.0
  2. Create new project:
    a. source "$HOME/.rye/env"
    b. cd /tmp/
    c. rye init junk; cd junk
  3. edit src/junk/init.py and add a useless import like "import pytz"
  4. Execute rye lint:
    a. rye lint
    b. rye lint --fix

Expected Result

Rye should both:

  1. recognize the error and offer "rye lint --fix" as an option (it does not)
  2. When specify --fix, it should fix the problem, which it does not.

Actual Result

:/tmp/junk]: rye lint
src/junk/__init__.py:1:8: F401 `pytx` imported but unused
  |
1 | import pytx
  |        ^^^^ F401
2 |
3 | def main() -> int:
  |
  = help: Remove unused import: `pytx`

Found 1 error.

and

:/tmp/junk]: rye lint --fix
src/junk/__init__.py:1:8: F401 `pytx` imported but unused
  |
1 | import pytx
  |        ^^^^ F401
2 |
3 | def main() -> int:
  |
  = help: Remove unused import: `pytx`

Found 1 error.

Version Info

:/tmp/junk]: rye --version
rye 0.41.0
commit: 0.41.0 (10d691d 2024-09-29)
platform: linux (x86_64)
self-python: [email protected]
symlink support: true
uv enabled: true

Stacktrace

No response

@pcarinhas
Copy link
Author

Also, running with -v:

:/tmp/junk]: rye lint --fix -v
[2024-10-13][15:42:25][ruff::resolve][DEBUG] Using Ruff default settings
[2024-10-13][15:42:25][ignore::walk][DEBUG] ignoring /tmp/junk/.venv: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/tmp/junk/.gitignore"), original: ".venv", actual: "**/.venv", is_whitelist: false, is_only_dir: false })))
[2024-10-13][15:42:25][ruff_workspace::resolver][DEBUG] Ignored path via `exclude`: "/tmp/junk/.ruff_cache"
[2024-10-13][15:42:25][ruff_workspace::resolver][DEBUG] Included path via `include`: "/tmp/junk/src/junk/__init__.py"
[2024-10-13][15:42:25][ruff_workspace::resolver][DEBUG] Included path via `include`: "/tmp/junk/pyproject.toml"
[2024-10-13][15:42:25][ruff_workspace::resolver][DEBUG] Ignored path via `exclude`: "/tmp/junk/.git"
[2024-10-13][15:42:25][ruff::commands::check][DEBUG] Identified files to lint in: 5.755612ms
[2024-10-13][15:42:25][ruff::diagnostics][DEBUG] Checking: /tmp/junk/src/junk/__init__.py
[2024-10-13][15:42:25][ruff::diagnostics][DEBUG] Checking: /tmp/junk/pyproject.toml
[2024-10-13][15:42:25][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'pytz' as Known(ThirdParty) (NoMatch)
[2024-10-13][15:42:25][ruff::commands::check][DEBUG] Checked 2 files in: 371.453µs
src/junk/__init__.py:1:8: F401 `pytz` imported but unused
  |
1 | import pytz
  |        ^^^^ F401
2 |
3 | def hello() -> str:
  |
  = help: Remove unused import: `pytz`

Found 1 error.

@pcarinhas
Copy link
Author

I tried using ruff directly from the .rye distribution and it also fails. So this may be a ruff issue:

~/.rye/self/bin]: ./ruff check --fix --fixable "F401" /tmp/junk/
/tmp/junk/src/junk/__init__.py:1:8: F401 `goodies` imported but unused
  |
1 | import goodies
  |        ^^^^^^^ F401
  |
  = help: Remove unused import: `goodies`

Found 1 error.

This also fails if I remove the --fixable option too.

@InSyncWithFoo
Copy link
Contributor

This is probably by design; fixes for F401 in __init__.py files are unsafe.

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

2 participants