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

Ruff Compatibility #69

Closed
siddk opened this issue Mar 19, 2023 · 3 comments
Closed

Ruff Compatibility #69

siddk opened this issue Mar 19, 2023 · 3 comments

Comments

@siddk
Copy link

siddk commented Mar 19, 2023

Hi! I'm trying to use Ruff (https://github.com/charliermarsh/ruff) as my Python linter, but getting some weird rule errors when plugging in to jaxtyping.

Here's a minimal example:

import numpy as np
from jaxtyping import Float32

def hello(x: Float32[np.ndarray, "batch dim"]) -> Float32[np.ndarray, "batch"]:
    return x[:, 1]

if __name__ == "__main__":
    print(hello(np.random.randn(10, 8)))

Running ruff minimal.py (the above file) results in two errors:

  • F722 "Syntax error in forward annotation: batch dim"
  • F821 "Undefined name batch"

Not sure if this is a jaxtyping or a ruff problem, but saw that jaxtyping is using Ruff to lint now, so curious if this has come up!

@siddk
Copy link
Author

siddk commented Mar 19, 2023

I see that F722 is ignored in the repo's pyproject.toml; however ignoring F821 doesn't quite feel safe.

@patrick-kidger
Copy link
Owner

Take a look at the FAQ regarding flake8 compatibility. I'll update that now to also mention Ruff, which uses the same ruleset.

In your example, that means ignoring F721, and then switching the return annotation to be " batch" rather than "batch".

@siddk
Copy link
Author

siddk commented Mar 19, 2023

Thanks so much, that fixed things! Appreciate the explanation in the FAQ as well.

@siddk siddk closed this as completed Mar 19, 2023
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