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

Python 3.10: Parenthesized context managers #203

Open
gfokkema opened this issue Jan 17, 2022 · 3 comments
Open

Python 3.10: Parenthesized context managers #203

gfokkema opened this issue Jan 17, 2022 · 3 comments

Comments

@gfokkema
Copy link

Besides match case, python 3.9 alpha6 / 3.10 also added parenthesized imports and context-managers.
Parenthesized imports works no problem in jedi, but parenthesized context managers lead to a syntax error:

>>> import jedi
>>> source = '''
... with (
...     open('/dev/stdout', 'w') as a,
...     open('/dev/stdout', 'w') as b,
... ):
...     a.write('a')
...     b.write('b')
... '''
>>> script = jedi.Script(source, path='example.py')
>>> [print(x, x.get_message()) for x in script.get_syntax_errors()]
<SyntaxError from=(3, 29) to=(3, 31)> SyntaxError: invalid syntax
<SyntaxError from=(4, 29) to=(4, 31)> SyntaxError: invalid syntax
<SyntaxError from=(5, 0) to=(5, 1)> SyntaxError: invalid syntax
<SyntaxError from=(6, 0) to=(6, 4)> IndentationError: unexpected indent

See:

Probably relates to:

@davidhalter davidhalter transferred this issue from davidhalter/jedi Jan 17, 2022
@davidhalter
Copy link
Owner

Moved to parso. As you said this is a more general issue with the PEG grammar (parso is only able to parse LL at the moment).

@isidentical
Copy link
Collaborator

@davidhalter if we agree on some sort of a verification process (or use the existing syntax error generation), we could simply add a rule like this:

namedexpr_test: asexpr_test [':=' asexpr_test]
asexpr_test: test ['as' test]

Which in theory (and also in practice, currently used by black) allows parenthesized context managers. Then if this is used anywhere outside of a with-statement's context expression, we would raise an error. This would be another inconsistency in the grammar that would be eliminated in a later stage, just like the LHS of many expressions.

Not sure if you think this would worth the effort without the full pattern matching stuff though.

@davidhalter
Copy link
Owner

Not sure if you think this would worth the effort without the full pattern matching stuff though.

Yeah, that's mostly what I'm worried about as well. It's a good idea, but full pattern matching is probably the more pressing issue.

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

No branches or pull requests

3 participants