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

Valid python files, that fails to parse in ruff #7632

Closed
qarmin opened this issue Sep 24, 2023 · 5 comments · Fixed by #7722
Closed

Valid python files, that fails to parse in ruff #7632

qarmin opened this issue Sep 24, 2023 · 5 comments · Fixed by #7722
Labels
bug Something isn't working parser Related to the parser

Comments

@qarmin
Copy link

qarmin commented Sep 24, 2023

Ruff 0.0.291
Cpython 3.11.4

Tested with

ruff format . --check

and cpython part

python -m compileall .

RuffBroken.zip

Example of file

from ..const import d#ta_source_const

def validate_incming_payload(baseballdc_request):

    requested_data_source_trimmed = baseballdc_request['data_source'].strip().upper()

    if(requested_data_source_trimmed not in data_source_const.DATA_SOURCE_LIST):
        raise ValueError(generate_data_source_error_message(baseballdc_request))

def generate_data_source_error_message(baseballdc_request): 

    requested_data_source = baseballdc_request['data_source']
    valid_data_sources = data_source_cons.DATA_SOURCE_LIST

    error_message_text = 'Value error in the incoming request payload:'
    data_sourcÛ_error_text = f'The data source requested ("{requested_data_source}") was not valid.'
    valid_data_source_text = f'The current list of valid datasources to choose from for basblldc is: {valid_data_sources}'

    return f'{error_message_text}\n\n{data_source_erro%_text}\{valid_data_source_text}\n';

error

error: Failed to format 48_IDX_0_RAND_14765242697460627399.py: source contains syntax errors: ParseError { error: Lexical(FStringError(SingleRbrace)), offset: 908, source_path: "<filename>" }
@charliermarsh charliermarsh added bug Something isn't working parser Related to the parser labels Sep 24, 2023
@dhruvmanila
Copy link
Member

The following files contains f-string errors which will be fixed by #7376. I've verified that those files are parsed without any errors on that branch:

  • 335_IDX_0_RAND_13905148532772824398.py
  • 48_IDX_0_RAND_14765242697460627399.py
  • 586_IDX_0_RAND_36061242038301280.py
  • 855_IDX_0_RAND_15689123331827052431.py

Other files contains identifier starting with unicode character which we're unable to identify which then produces a syntax error.

@qarmin
Copy link
Author

qarmin commented Sep 29, 2023

Looks that #7376 introduced regression, and now some valid python files shows errors:

error: Failed to format 549_IDX_0_RAND_5726799750657298695.py: source contains syntax errors: LexicalError { error: FStringError(UnterminatedString), location: 3282 }
error: Failed to format 230_IDX_0_RAND_14394415519784108053.py: source contains syntax errors: ParseError { error: UnrecognizedToken(For, None), offset: 1799, source_path: "<filename>" }

RuffBroken.zip

@MichaReiser
Copy link
Member

Looks that #7376 introduced regression, and now some valid python files shows errors:

error: Failed to format 549_IDX_0_RAND_5726799750657298695.py: source contains syntax errors: LexicalError { error: FStringError(UnterminatedString), location: 3282 }
error: Failed to format 230_IDX_0_RAND_14394415519784108053.py: source contains syntax errors: ParseError { error: UnrecognizedToken(For, None), offset: 1799, source_path: "<filename>" }

RuffBroken.zip

CC: @dhruvmanila

@charliermarsh
Copy link
Member

@dhruvmanila - We should probably try to fix these regressions before the next release. I can also help out if needed.

@dhruvmanila
Copy link
Member

230_IDX_0_RAND_14394415519784108053.py: This fails on 3.12.0rc3 as well because the generator is missing the parentheses. I'm surprised that it parses on 3.11. Maybe it's because the parentheses were added manually? Atleast in our case we did the expression parsing by adding the surrounding parentheses manually. So,

- f"', '.join({ckt.name for ckt in self._ckts_with_errors})"
+ f"', '.join({(ckt.name for ckt in self._ckts_with_errors)})"

It fails in the same way the below code fails:

foo = ckt.name for ckt in self._ckts_with_errors

549_IDX_0_RAND_5726799750657298695.py: This is failing because of Windows newline. A minimal repro:

f'text \\r\n
more text'

dhruvmanila added a commit that referenced this issue Oct 1, 2023
## Summary

This PR fixes a bug where if a Windows newline (`\r\n`) character was
escaped, then only the `\r` was consumed and not `\n` leading to an
unterminated string error.

## Test Plan

Add new test cases to check the newline escapes.

fixes: #7632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser Related to the parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants