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

Different errors being reported on the same file depending on whether parsing from stdin or not #6627

Closed
bryanforbes opened this issue Aug 16, 2023 · 0 comments · Fixed by #6628
Assignees
Labels
bug Something isn't working

Comments

@bryanforbes
Copy link

Given the following file named foo.pyi:

from pathlib import Path

def get_home_directory() -> Path: ...

ruff reports different errors depending on whether it's being parsed from stdin. The following reports no errors:

ruff --force-exclude --no-cache --no-fix --quiet --format json --isolated --select TCH asyncpg-stubs/compat.pyi

And the following reports an error in the first line:

cat foo.pyi | ruff --force-exclude --no-cache --no-fix --quiet --format json --isolated --select TCH --stdin-filename path/to/foo.pyi -

The reason this is coming up is because ruff-lsp runs ruff similar to how the second command runs and is reporting errors in my stubs project.

@charliermarsh charliermarsh self-assigned this Aug 16, 2023
@charliermarsh charliermarsh added the bug Something isn't working label Aug 16, 2023
charliermarsh added a commit that referenced this issue Aug 16, 2023
## Summary

When running Ruff from stdin, we were always falling back to the default
source type, even if the user specified a path (as is the case when
running from the LSP). This PR wires up the source type inference, which
means we now get the expected result when checking `.pyi` and `.ipynb`
files.

Closes #6627.

## Test Plan

Verified that `cat
crates/ruff/resources/test/fixtures/jupyter/valid.ipynb | cargo run -p
ruff_cli -- --force-exclude --no-cache --no-fix --isolated --select ALL
--stdin-filename foo.ipynb -` yielded the expected results (and differs
from the errors you get if you omit the filename).

Verified that `cat foo.pyi | cargo run -p ruff_cli -- --force-exclude
--no-cache --no-fix --format json --isolated --select TCH
--stdin-filename path/to/foo.pyi -` yielded no errors.
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