-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
bpo-33064: lib2to3: support trailing comma after **kwargs #6096
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ | |
| # Testing imports | ||
| from . import support | ||
| from .support import driver, driver_no_print_statement | ||
| from test.support import verbose | ||
|
|
||
| # Python imports | ||
| import difflib | ||
|
|
@@ -22,7 +21,6 @@ | |
| import sys | ||
| import tempfile | ||
| import unittest | ||
| import warnings | ||
|
|
||
| # Local imports | ||
| from lib2to3.pgen2 import driver as pgen2_driver | ||
|
|
@@ -305,6 +303,38 @@ def test_8(self): | |
| *g:6, h:7, i=8, j:9=10, **k:11) -> 12: pass""" | ||
| self.validate(s) | ||
|
|
||
| def test_9(self): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to add tests for signatures like: and few combinations if they have a separate path in the grammar.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LOL, that's one subtle way to signal "your patch doesn't handle the vararg case" ;-) Alright, I added |
||
| s = """def f( | ||
| a: str, | ||
| b: int, | ||
| *, | ||
| c: bool = False, | ||
| **kwargs, | ||
| ) -> None: | ||
| call(c=c, **kwargs,)""" | ||
| self.validate(s) | ||
|
|
||
| def test_10(self): | ||
| s = """def f( | ||
| a: str, | ||
| ) -> None: | ||
| call(a,)""" | ||
| self.validate(s) | ||
|
|
||
| def test_11(self): | ||
| s = """def f( | ||
| a: str = '', | ||
| ) -> None: | ||
| call(a=a,)""" | ||
| self.validate(s) | ||
|
|
||
| def test_12(self): | ||
| s = """def f( | ||
| *args: str, | ||
| ) -> None: | ||
| call(*args,)""" | ||
| self.validate(s) | ||
|
|
||
|
|
||
| # Adapted from Python 3's Lib/test/test_grammar.py:GrammarTests.test_var_annot | ||
| class TestVarAnnotations(GrammarTest): | ||
|
|
@@ -407,7 +437,7 @@ def test_new_syntax(self): | |
| self.validate("class B(t, *args): pass") | ||
| self.validate("class B(t, **kwargs): pass") | ||
| self.validate("class B(t, *args, **kwargs): pass") | ||
| self.validate("class B(t, y=9, *args, **kwargs): pass") | ||
| self.validate("class B(t, y=9, *args, **kwargs,): pass") | ||
|
|
||
|
|
||
| class TestParserIdempotency(support.TestCase): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| lib2to3 now properly supports trailing commas after ``*args`` and | ||
| ``**kwargs`` in function signatures. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it be just
tfpdef ['=' test] [',']? Of course may be there are reasons of writing the rule as it is written due to the parser limitations.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe but I want to keep this as close to Grammar/Grammar and this is how it's voiced there.