Skip to content

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
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.

2 participants