This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Removal of Tuple Parameter Unpacking [PEP3113]
Type: Stage:
Components: None Versions: Python 3.0
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: brett.cannon, jimjjewett, tonylownds
Priority: normal Keywords: patch

Created on 2007-03-10 21:34 by tonylownds, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
refmanual.patch tonylownds, 2007-03-11 22:34
simplified-args.patch tonylownds, 2007-03-12 15:07
latest.diff brett.cannon, 2007-05-13 03:09 against r55280 w/ bcannon's revisions
Messages (12)
msg52154 - (view) Author: Tony Lownds (tonylownds) Date: 2007-03-10 21:34
Remove tuple parameter unpacking. The Grammar is now:

typedargslist: ((tfpdef ['=' test] ',')*
                ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef)
                | tfpdef ['=' test] (',' tfpdef ['=' test])* [','])
tfpdef: NAME [':' test]
varargslist: ((vfpdef ['=' test] ',')*
              ('*' [vfpdef] (',' vfpdef ['=' test])*  [',' '**' vfpdef] | '**' vfpdef)
              | vfpdef ['=' test] (',' vfpdef ['=' test])* [','])
vfpdef: NAME

Tuple parameters are removed from Lib/.
msg52155 - (view) Author: Tony Lownds (tonylownds) Date: 2007-03-11 22:34
File Added: refmanual.patch
msg52156 - (view) Author: Tony Lownds (tonylownds) Date: 2007-03-12 15:07
I found some more code to be removed + a docstring fix in inspect.py. getfullargspec's docstring lists the 
wrong order for return values. This patch combined the refmanual patch, previous simplified args patch, 
and 2to3 changes on some doc building tools.

File Added: simplified-args.patch
msg52157 - (view) Author: Jim Jewett (jimjjewett) Date: 2007-03-22 12:47
Not sure if any of these are really problems, and it looks like Tony already looked them over before submitting, but still worth mentioning...

(1)  This does more than take out tuples, though the other changes do also look like things that ought to change for py3k.

(2)  I was amused by the name "stuff", but I couldn't think of a better name for that particular grouping.  (suffix, mode, type)

(3)  There are some signature changes, where the unpacking is now done by the caller, such as 

 class LeftShift(Node):
-    def __init__(self, (left, right), lineno=None):
+    def __init__(self, left, right, lineno=None):

(4)  The pdb change marks could be shortened a bit.  That shouldn't matter for patching, but I'll post it here since it helped me.

-    def user_exception(self, frame, (exc_type, exc_value, exc_traceback)):
+    def user_exception(self, frame, exc_info):
         """This function is called if an exception occurs,
         but only if we are to stop at or just below this level."""
+        (exc_type, exc_value, exc_traceback) = exc_info
         frame.f_locals['__exception__'] = exc_type, exc_value      
-        if type(exc_type) == type(''):
-            exc_type_name = exc_type
-        else: exc_type_name = exc_type.__name__
+        exc_type_name = exc_type.__name__
         print(exc_type_name + ':', _saferepr(exc_value), file=self.stdout)
         self.interaction(frame, exc_traceback)
msg52158 - (view) Author: Jim Jewett (jimjjewett) Date: 2007-03-22 12:57
On the reprs, is there a reason to call repr instead of using %r?

For example, the Floordiv repr changed to:

"FloorDiv(%s, %s)" % (repr(self.left), repr(self.right))

Why not "FloorDiv(%r, %r)" % (self.left, self.right)

or even, (assuming PEP 3101 with locals,)

"FloorDiv({self.left:r}, {self.right:r})".format()
msg52159 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2007-03-22 19:57
Chances are I will take Tony's patch for its removal of the feature and use 2to3 to handle the conversion as much as possible.
msg52160 - (view) Author: Tony Lownds (tonylownds) Date: 2007-03-22 21:53
Thanks for the comments.

Re: "stuff", if you look at other parts of the code, that is how the triple is referred to -- fyi on how the name "stuff" came to be :) I was also at a loss for a better name, and went with the contextual references.

Re: using 2to3 -- Brett, in many cases I actually tried to come up with a consistent name. IIRC 2to3 will put in XXX_fixme_123 or something like that. Or it did when I last tried. Anyway, if you end up using 2to3, I would really appreciate it if you also picked up the inspect.py docstring change.

Re: signature changes (eg LeftShift) and repr (FloorDiv) -- that is generated code, and that is why "repr" is used. I chose to change the generation source rather than the generation machinery as I was changing the source anyway, to account for the changes to parameter syntax. That is why there are API changes. Given that other API changes were made and those class constructors are more or less an internal API (created through compiler.parse),
I believe this is the best way of dealing with the changes.

Brett, If you need me to remove the 2to3 doc toolchain patches, I can do that.
msg52161 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2007-03-22 23:59
The reason I mention using 2to3 is Collin has done a bunch of work on it in order to make it also work with lambda.  I believe he also cleaned up the generated names.

And as for cleaning up the patches, Tony, I can easily edit the diff file manually, but thanks for the offer.  But if I need you to I will let you know.
msg52162 - (view) Author: Jim Jewett (jimjjewett) Date: 2007-03-23 16:30
Brett,

2to3 is an important tool, but probably won't ever match good hand-work.

(1)  There are several places where he improved the code.

replacing map + an unpacking nested function with a generator:
"""
 def classify_class_attrs(object):
     """Wrap inspect.classify_class_attrs, with fixup for data descriptors."""
-    def fixup((name, kind, cls, value)):
+    for (name, kind, cls, value) in inspect.classify_class_attrs(object):
         if inspect.isdatadescriptor(value):
             kind = 'data descriptor'
-        return name, kind, cls, value
-    return map(fixup, inspect.classify_class_attrs(object))
+        yield name, kind, cls, value
"""


Replacing a paren-laden lambda with named function:
"""
-            items = sorted(items, key=lambda (k, v): (str(type(k)), k, v))
+            def sortkey(item):
+                key, value = item
+                return str(type(key)), key, value
+            items = sorted(items, key=sortkey)
"""

Replacing filter + lambda + unpack with list comprehension:
"""
-        attrs = filter(lambda (name, kind, cls, value): visiblename(name),
-                       classify_class_attrs(object))
+        attrs = [(name, kind, cls, value)
+                 for name, kind, cls, value in classify_class_attrs(object)
+                 if visiblename(name)]
"""


(2)  His names are better.

I prefer his (name, result, expected)) over the current (name, (v1,v2), (e1,e2))), let alone (name, _v1_v2_, _e1_e2_))

Even looking just at code with good existing names, he uses components instead of _scheme_netloc_url_query_fragment_

So we get (what looks like human-readable source)

-def urlunsplit((scheme, netloc, url, query, fragment)):
+def urlunsplit(components):
+    (scheme, netloc, url, query, fragment) = components

instead of (what looks like the output of a computer translation step)

+def urlunsplit(_scheme_netloc_url_query_fragment_):
+    (scheme, netloc, url, query, fragment) = _scheme_netloc_url_query_fragment_


msg52163 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2007-05-05 05:08
Just so that Tony knows, this patch is next on my TODO list for Python.  And I will be reviewing your patch instead of doing a blind 2to3 translation.
msg52164 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2007-05-13 03:09
I have uploaded the current patch I am working off of.  Basically the only difference is a style choice of not having parentheses in automatic unpacking.  I also kept a method in the compiler package that was slated to be removed.

But as of r55280, test_compiler and test_transformer are failing.  I don't know the compiler package at all, so if you can have a look, Tony, I would really appreciate it.
File Added: latest.diff
msg52165 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2007-05-14 23:47
OK, committed on revision 55329 and 55332.  Thanks, Tony!
History
Date User Action Args
2022-04-11 14:56:23adminsetgithub: 44692
2008-01-06 22:29:46adminsetkeywords: - py3k
versions: + Python 3.0
2007-03-10 21:34:17tonylowndscreate