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

black/parser: partial support for pattern matching #2586

Merged
merged 10 commits into from Nov 14, 2021

Conversation

isidentical
Copy link
Collaborator

@isidentical isidentical commented Nov 3, 2021

Partial implementation for #2242. Only works when explicitly stated -t py310.

@ichard26 ichard26 added C: blib2to3 C: parser How we parse code. Or fail to parse it. labels Nov 3, 2021
@ichard26
Copy link
Collaborator

ichard26 commented Nov 6, 2021

FWIW I can't get this valid code to parse under this PR:

value = (1, 2)

match value:
    case x, y:
        pass

@ichard26
Copy link
Collaborator

ichard26 commented Nov 6, 2021

And of course CI is also broken due to recent changes in some third party packages, sigh.

@isidentical isidentical marked this pull request as ready for review November 9, 2021 12:41
@isidentical
Copy link
Collaborator Author

I've not included the 3.10 grammar among the default ones, since it is pretty experimental at the moment (and might have other, unknown problems). But it can be activated through specifying target_versions= {3.10}. I also added some tests. Hopefully after fixing the CI (which I am not really sure why it is failing), this should be ready for a review.

@ichard26
Copy link
Collaborator

ichard26 commented Nov 9, 2021

re. failing CI

There's multiple layers to it (none which are your fault). A recent release of coverage broke the coverage upload step of the test jobs, a recent change in hypothesis makes our primer configuration broken currently, and finally my Python two deprecation code doesn't withstand parser changes well, should be fixed by #2592.

p.s. I'm writing on a phone so my apologies for the terseness

@kukushking kukushking mentioned this pull request Nov 10, 2021
1 task
@Zac-HD
Copy link
Contributor

Zac-HD commented Nov 10, 2021

a recent change in hypothesis makes our primer configuration broken currently

Is this something I should know about as Hypothesis dev?

(also I love pinning deps with pip-compile, happy to write up a detailed issue if that would be of interest)

@ichard26
Copy link
Collaborator

@Zac-HD oh don't worry about it! We have a development tool called black-primer and its job to run Black over millions of lines of code (by formatting a large array of OSS projects) to assure it doesn't crash or do other weird stuff. Hypothesis happens to be one of the projects and it seems like one of your in-tree development tools was recently made Python 3.8<= which broke the primer workflow on 3.7 and below. I've already fixed by marking Hypothesis as a 3.8+ project in the primer config.

@ichard26 ichard26 requested review from ichard26 and JelleZijlstra and removed request for ichard26 November 12, 2021 01:50
Copy link
Collaborator

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exciting!

If I remember correctly this also makes parenthesized with statements work thanks to parser magic. Should we add tests for that?

@Zac-HD
Copy link
Contributor

Zac-HD commented Nov 12, 2021

it seems like one of your in-tree development tools was recently made Python 3.8<= which broke the primer workflow on 3.7 and below. I've already fixed by marking Hypothesis as a 3.8+ project in the primer config.

Ah, yep, the Array API standard requires Python 3.8+ and therefore our new extension for it does too.

@isidentical isidentical force-pushed the basic-support-for-soft-keywords branch from e046c14 to d16f6c7 Compare November 13, 2021 08:58
@isidentical isidentical force-pushed the basic-support-for-soft-keywords branch from d16f6c7 to 49096af Compare November 13, 2021 09:01
@isidentical
Copy link
Collaborator Author

If I remember correctly this also makes parenthesized with statements work thanks to parser magic. Should we add tests for that?

Added tests for that, nice catch! I'll also work on some more patterns for the PEP 634 in the upcoming PRs, but hopefully as is this PR should cover some of the basic cases for both of them. (not sure if there is anything else needed for the context managers).

Copy link
Collaborator

@ichard26 ichard26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome to see 3.9 and 3.10 compatibility truly realized, thank you!

@Kurt-von-Laven
Copy link

Is more work needed here, or can this PR be merged?

@JelleZijlstra JelleZijlstra merged commit 1e0ec54 into psf:main Nov 14, 2021
JelleZijlstra pushed a commit that referenced this pull request Nov 16, 2021
Partial implementation for #2242. Only works when explicitly stated -t py310.

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
nrser added a commit to nrser/docspec that referenced this pull request Feb 22, 2023
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.
nrser added a commit to nrser/docspec that referenced this pull request Feb 22, 2023
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.
nrser added a commit to nrser/docspec that referenced this pull request Feb 26, 2023
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 added a commit to NiklasRosenstein/python-docspec that referenced this pull request Mar 9, 2023
)

* Use blib2to3 parser to support match statement

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.

* Add a _unreleased changelog for blib2to3 integration

* fix mypy in docspec/src/docspec/__init__.py

* fix mypy

* update changelog format

* update GitHub workflow

* fix workflow

* insert PR url

* use `--no-venv-check` also for `slap run` in docs job

---------

Co-authored-by: Niklas Rosenstein <rosensteinniklas@gmail.com>
@ambv ambv mentioned this pull request Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: parser How we parse code. Or fail to parse it.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants