]> granicus.if.org Git - python/commitdiff
bpo-33348: parse expressions after * and ** in lib2to3 (GH-6586)
authorZsolt Dollenstein <zsol.zsol@gmail.com>
Thu, 24 Oct 2019 06:19:07 +0000 (23:19 -0700)
committerMiss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 24 Oct 2019 06:19:07 +0000 (23:19 -0700)
These are valid even in python 2.7

https://bugs.python.org/issue33348

Automerge-Triggered-By: @gpshead
Lib/lib2to3/Grammar.txt
Lib/lib2to3/fixes/fix_apply.py
Lib/lib2to3/fixes/fix_intern.py
Lib/lib2to3/fixes/fix_reload.py
Lib/lib2to3/tests/test_parser.py
Misc/NEWS.d/next/Library/2018-04-24-13-18-48.bpo-33348.XaJDei.rst [new file with mode: 0644]

index a7ddad3cf322c5fad91c24218db7bcea92c917e0..68b73868b58282fce8ad32809c6350f587706090 100644 (file)
@@ -138,8 +138,8 @@ arglist: argument (',' argument)* [',']
 # that precede iterable unpackings are blocked; etc.
 argument: ( test [comp_for] |
             test '=' test |
-           '**' expr |
-           star_expr )
+            '**' test |
+               '*' test )
 
 comp_iter: comp_for | comp_if
 comp_for: [ASYNC] 'for' exprlist 'in' testlist_safe [comp_iter]
index 826ec8c9b62abbbef3516345b02ea9ea77915c22..6408582c42647741416968f92c351a5581bc5e3e 100644 (file)
@@ -37,10 +37,8 @@ class FixApply(fixer_base.BaseFix):
         # I feel like we should be able to express this logic in the
         # PATTERN above but I don't know how to do it so...
         if args:
-            if args.type == self.syms.star_expr:
-                return  # Make no change.
             if (args.type == self.syms.argument and
-                args.children[0].value == '**'):
+                args.children[0].value in {'**', '*'}):
                 return  # Make no change.
         if kwds and (kwds.type == self.syms.argument and
                      kwds.children[0].value == '**'):
index a852330908bd9f4cf72c35a1cc6455cab477975d..d752843092aacd8bc6e84c80f5bc6116563b9d25 100644 (file)
@@ -30,10 +30,8 @@ class FixIntern(fixer_base.BaseFix):
             # PATTERN above but I don't know how to do it so...
             obj = results['obj']
             if obj:
-                if obj.type == self.syms.star_expr:
-                    return  # Make no change.
                 if (obj.type == self.syms.argument and
-                    obj.children[0].value == '**'):
+                    obj.children[0].value in {'**', '*'}):
                     return  # Make no change.
         names = ('sys', 'intern')
         new = ImportAndCall(node, results, names)
index 6c7fbbd3be3fb3b8e70f5432643d328a1d1df381..b30841131c51f9b6311d1e10629dd9e5049fd6ab 100644 (file)
@@ -27,10 +27,8 @@ class FixReload(fixer_base.BaseFix):
             # PATTERN above but I don't know how to do it so...
             obj = results['obj']
             if obj:
-                if obj.type == self.syms.star_expr:
-                    return  # Make no change.
                 if (obj.type == self.syms.argument and
-                    obj.children[0].value == '**'):
+                    obj.children[0].value in {'**', '*'}):
                     return  # Make no change.
         names = ('importlib', 'reload')
         new = ImportAndCall(node, results, names)
index f22d399b3403f3a5e977dd9b8b3a15bd608b603d..a0c31e8f5300ddfc73bcdf77e40b4eb9deb876b3 100644 (file)
@@ -253,6 +253,13 @@ class TestUnpackingGeneralizations(GrammarTest):
     def test_double_star_dict_literal_after_keywords(self):
         self.validate("""func(spam='fried', **{'eggs':'scrambled'})""")
 
+    def test_double_star_expression(self):
+        self.validate("""func(**{'a':2} or {})""")
+        self.validate("""func(**() or {})""")
+
+    def test_star_expression(self):
+        self.validate("""func(*[] or [2])""")
+
     def test_list_display(self):
         self.validate("""[*{2}, 3, *[4]]""")
 
diff --git a/Misc/NEWS.d/next/Library/2018-04-24-13-18-48.bpo-33348.XaJDei.rst b/Misc/NEWS.d/next/Library/2018-04-24-13-18-48.bpo-33348.XaJDei.rst
new file mode 100644 (file)
index 0000000..f95a73f
--- /dev/null
@@ -0,0 +1,2 @@
+lib2to3 now recognizes expressions after ``*`` and `**` like in ``f(*[] or
+[])``.