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

Use blib2to3 parser from black package to support match statement #80

Merged
merged 9 commits into from Mar 9, 2023

Conversation

nrser
Copy link
Contributor

@nrser nrser commented Mar 1, 2023

In response to issue #79.

The built-in lib2to3 does not support pattern matching (Python 3.10+):

https://docs.python.org/3.11/library/2to3.html#module-lib2to3

The black project managed to get some level of parsing support for
match out of their modified version blib2to3, see:

  1. Support Python 3.10 pattern matching syntax psf/black#2242
  2. black/parser: partial support for pattern matching psf/black#2586

This change adds black as a dependency and switches to using
blib2to3 to parse.

Tests pass, and I am currently using it on an actual project of moderate complexity, but this is a significant change to core functionality... caution is advised. It seems like blib2to3 itself is a bit of hack/stop-gap, and that's not counting my hasty integration with docspec-python.

However, for users now in a broken state due to match syntax in their source files this may be worth a shot.

The built-in lib2to3 does not support pattern matching (Python 3.10+):

https://docs.python.org/3.11/library/2to3.html#module-lib2to3

The [black][] project managed to get some level of parsing support for
`match` out of their modified version `blib2to3`, see:

1.  psf/black#2242
2.  psf/black#2586

[black]: https://github.com/psf/black

This change adds `black` as a dependency and switches to using
`blib2to3` to parse. Tests pass, but that's all that's been attempted
thus far.
@NiklasRosenstein
Copy link
Owner

Thanks a lot for this @nrser 🙌 I hope I can take a closer look later this week.

blib2to3 does indeed sound like a stop gap solution, but I'm happy to use it as long as it unblocks using docspec with the new syntax. I was hoping to migrating to libCST in the future (#3) but that's a big chunk of work.

@NiklasRosenstein
Copy link
Owner

The update-changelogs task action isn't really working for PRs from forks I guess (NiklasRosenstein/slap#90), so I'm ignoring that failed test.

Thanks a lot for this @nrser!

@NiklasRosenstein NiklasRosenstein merged commit 1db8d16 into NiklasRosenstein:develop Mar 9, 2023
11 of 12 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants