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.

Author jimjjewett
Recipients
Date 2007-03-23.16:30:54
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
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_


History
Date User Action Args
2007-08-23 15:57:27adminlinkissue1678060 messages
2007-08-23 15:57:27admincreate