[Jython-checkins] jython: Handle dotted attribute strings correctly in attrgetter.

frank.wierzbicki jython-checkins at python.org
Fri Jun 22 20:37:57 CEST 2012


http://hg.python.org/jython/rev/862389f47315
changeset:   6733:862389f47315
user:        Jezreel Ng <jezreel at gmail.com>
date:        Fri Jun 22 11:15:26 2012 -0700
summary:
  Handle dotted attribute strings correctly in attrgetter.

files:
  Lib/test/test_operator.py            |  1 -
  src/org/python/modules/operator.java |  6 +++++-
  2 files changed, 5 insertions(+), 2 deletions(-)


diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py
--- a/Lib/test/test_operator.py
+++ b/Lib/test/test_operator.py
@@ -367,7 +367,6 @@
         self.failIf(operator.is_not(a, b))
         self.failUnless(operator.is_not(a,c))
 
-    @unittest.skip("FIXME: broken")
     def test_attrgetter(self):
         class A:
             pass
diff --git a/src/org/python/modules/operator.java b/src/org/python/modules/operator.java
--- a/src/org/python/modules/operator.java
+++ b/src/org/python/modules/operator.java
@@ -325,7 +325,11 @@
                 throw Py.TypeError(String.format("attribute name must be string, not '%.200s'",
                                                  name.getType().fastGetName()));
             }
-            return obj.__getattr__(nameStr.intern());
+            String[] components = nameStr.split("\\.");
+            for (String component : components) {
+                obj = obj.__getattr__(component.intern());
+            }
+            return obj;
         }
 
     }

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list