Commits

Anonymous committed ee2e1d8

Fix issue #15: AttributeError on $(this)

  • Participants
  • Parent commits 65f7b7e

Comments (0)

Files changed (2)

pyquery/pyquery.py

         length = len(args)
         if length == 0:
             raise ValueError('You must provide at least a selector')
-        if len(args) == 1 and not args[0].startswith('<'):
+        if len(args) == 1 and isinstance(args[0], str) and not args[0].startswith('<'):
             args += (self,)
         result = self.__class__(*args, **dict(parent=self))
         return result
         doc = pq(url='http://example.com', opener=opener)
         assert len(doc('.node')) == 1, doc
 
+class TestCallback(unittest.TestCase):
+    html = """
+        <ol>
+            <li>Coffee</li>
+            <li>Tea</li>
+            <li>Milk</li>
+        </ol>
+    """
+    
+    def test_S_this_inside_callback(self):
+        S = pq(self.html)
+        self.assertEqual(S('li').map(lambda i, el: S(this).html()), ['Coffee', 'Tea', 'Milk'])
+        
 def application(environ, start_response):
     req = Request(environ)
     response = Response()