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

Rule B009 cause autofix error #7156

Closed
qarmin opened this issue Sep 5, 2023 · 6 comments
Closed

Rule B009 cause autofix error #7156

qarmin opened this issue Sep 5, 2023 · 6 comments
Labels
bug Something isn't working fuzzer Surfaced via fuzzing.

Comments

@qarmin
Copy link

qarmin commented Sep 5, 2023

Ruff 0.0.287 (latest changes from main branch)

ruff  *.py --select B009 --no-cache --fix

file content(at least simple cpython script shows that this is valid python file):

def sql_quantile(is_analytic=False):
    sa_func = getattr(sql.func, "percentile_co³t")

error

/home/rafal/test/tmp_folder/661_IDX_0_RAND_23867792595500675638023.py:2:15: B009 Do not call `getattr` with a constant attribute value. It is not any safer than normal property access.
Found 1 error.

error: Autofix introduced a syntax error. Reverting all changes.

This indicates a bug in `ruff`. If you could open an issue at:

    https://github.com/astral-sh/ruff/issues/new?title=%5BAutofix%20error%5D

...quoting the contents of `/home/rafal/test/tmp_folder/661_IDX_0_RAND_23867792595500675638023.py`, the rule codes B009, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

python_compressed.zip

@zanieb
Copy link
Member

zanieb commented Sep 5, 2023

I guess we need to guard against strings that cannot be tokenized?

error: Autofix introduced a syntax error in `example.py` with rule codes B009: Got unexpected token ³ at byte offset 73
---
def sql_quantile(is_analytic=False):
    sa_func = sql.func.percentile_co³t

@zanieb zanieb added bug Something isn't working fuzzer Surfaced via fuzzing. labels Sep 5, 2023
@charliermarsh
Copy link
Member

Is that actually invalid code though? Or is it a bug in the lexer?

@zanieb
Copy link
Member

zanieb commented Sep 5, 2023

❯ python example.py
  File "/Users/mz/eng/src/astral-sh/ruff/example.py", line 2
    sa_func = sql.func.percentile_co³t
                                    ^
SyntaxError: invalid character '³' (U+00B3)

@charliermarsh
Copy link
Member

Hmm, we need to understand why that character is invalid, because Python does allow some unicode characters in identifiers. Ideally is_identifier would account for this.

@charliermarsh
Copy link
Member

I guess the spec is stricter than what we've implemented: https://docs.python.org/3/reference/lexical_analysis.html#identifiers / https://peps.python.org/pep-3131/

@zanieb
Copy link
Member

zanieb commented Sep 5, 2023

Tracking in #7169

@zanieb zanieb closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fuzzer Surfaced via fuzzing.
Projects
None yet
Development

No branches or pull requests

3 participants