NiklasRosenstein / python-docspec

Docspec is a JSON object specification for representing API documentation of programming languages.
https://niklasrosenstein.github.io/python-docspec/
Other
15 stars 5 forks source link

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

Closed nrser closed 1 year ago

nrser commented 1 year ago

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. https://github.com/psf/black/issues/2242
  2. https://github.com/psf/black/pull/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.

NiklasRosenstein commented 1 year ago

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 commented 1 year ago

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

Thanks a lot for this @nrser!