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

Unable to format 3.10 code with a match statement #216

Closed
cooperlees opened this issue Oct 3, 2022 · 2 comments
Closed

Unable to format 3.10 code with a match statement #216

cooperlees opened this issue Oct 3, 2022 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@cooperlees
Copy link

I believe I have valid python 3.10 syntax in nmapsanner.py as my running + unittests pass. Should this code be supported by usort main? If not, here is some sample code to work with to add support.

Error and repro

  • git clone git@github.com:cooperlees/nmapscanner.git
  • python3 -m venv /tmp/test_usort
  • /tmp/test_usort/bin/pip install git+https://github.com/facebook/usort
cooper@l33t:~/repos/nmapscanner$ /tmp/test_usort/bin/usort check .
Error sorting nmapscanner.py: Syntax Error @ 220:11.
Incomplete input. Encountered 'output_format', but expected ';', or 'NEWLINE'.

    match output_format:
          ^
Would sort nmapscanner.py

Cheers

@cooperlees cooperlees added the bug Something isn't working label Oct 3, 2022
@amyreese
Copy link
Member

amyreese commented Oct 3, 2022

I think this is because LibCST only supports 3.10 syntax using the new rust parser, which is not yet enabled by default. Try setting LIBCST_PARSER_TYPE="native" in your environment when running µsort:

$ LIBCST_PARSER_TYPE=native usort check .

@cooperlees
Copy link
Author

Yup, that works. Should that be documented somewhere to save others being confused? What's the default plan? Can it maybe be default / set for >= 3.10? 3.10 is pretty common now.

crl-m1:usort cooper$ grep -R LIBCST_PARSER_TYPE *
crl-m1:usort cooper$

@amyreese amyreese added this to the 1.1 milestone Mar 12, 2023
@amyreese amyreese self-assigned this Mar 12, 2023
amyreese added a commit that referenced this issue Mar 12, 2023
Adds a helper function to detect the presence of the `libcst.native`
parser module, and enable its use in LibCST appropriately. If the native
module is not available, or it does not contain the `parse_module`
function that we expect to use, then the native parser is not enabled.

Adds support for parsing 3.10 match statements, as well as future syntax
that requires use of the PEG parsing features only available in LibCST's
native parser.

This is currently only enabled in the µsort CLI entrypoint. Programs
using the µsort API directly will need to call or enable the native
parser separately if desired.

Fixes #216

[ghstack-poisoned]
amyreese added a commit that referenced this issue Mar 12, 2023
Adds a helper function to detect the presence of the `libcst.native`
parser module, and enable its use in LibCST appropriately. If the native
module is not available, or it does not contain the `parse_module`
function that we expect to use, then the native parser is not enabled.

Adds support for parsing 3.10 match statements, as well as future syntax
that requires use of the PEG parsing features only available in LibCST's
native parser.

This is currently only enabled in the µsort CLI entrypoint. Programs
using the µsort API directly will need to call or enable the native
parser separately if desired.

Fixes #216

ghstack-source-id: 1cfca9b1e87903e4e4ea8ec0548c5b349c0e7300
Pull Request resolved: #244
amyreese added a commit that referenced this issue Mar 12, 2023
Adds a helper function to detect the presence of the `libcst.native`
parser module, and enable its use in LibCST appropriately. If the native
module is not available, or it does not contain the `parse_module`
function that we expect to use, then the native parser is not enabled.

Adds support for parsing 3.10 match statements, as well as future syntax
that requires use of the PEG parsing features only available in LibCST's
native parser.

This is currently only enabled in the µsort CLI entrypoint. Programs
using the µsort API directly will need to call or enable the native
parser separately if desired.

Fixes #216

[ghstack-poisoned]
amyreese added a commit that referenced this issue Mar 12, 2023
Adds a helper function to detect the presence of the `libcst.native`
parser module, and enable its use in LibCST appropriately. If the native
module is not available, or it does not contain the `parse_module`
function that we expect to use, then the native parser is not enabled.

Adds support for parsing 3.10 match statements, as well as future syntax
that requires use of the PEG parsing features only available in LibCST's
native parser.

This is currently only enabled in the µsort CLI entrypoint. Programs
using the µsort API directly will need to call or enable the native
parser separately if desired.

Fixes #216

ghstack-source-id: 71a1b574178e55e439220644d475b591fb3a6069
Pull Request resolved: #244
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

No branches or pull requests

2 participants