Edgewall Software

Opened 15 years ago

Closed 14 years ago

#324 closed defect (fixed)

Test fails for Genshi-0.5.1 and Python 2.6.2

Reported by: neurogeek@… Owned by: cmlenz
Priority: trivial Milestone: 0.6
Component: General Version: 0.5.1
Keywords: Cc: lmacken@…

Description

Hello there,

When running python setup.py test in Genshi-0.5.1 using python-2.6.2, I get a test failed for genshi.template.eval.Undefined in here:

"""Represents a reference to an undefined variable.
221	   
227	    >>> foo = Undefined('foo')
228	    >>> bool(foo)
229	    False
230	    >>> list(foo) -----> This line fail test
231	    []
232	    >>> print foo
233	    undefined

Thanks,

Attachments (1)

python-genshi-0.5.1-py2.6.2-length_hint.patch (492 bytes) - added by lmacken@… 15 years ago.
python-genshi-0.5.1-py2.6.2-length_hint.patch

Download all attachments as: .zip

Change History (6)

comment:1 Changed 15 years ago by lmacken@…

  • Cc lmacken@… added

When tweaking the class a little and running the tests::

    python-2.4.3-27.el5
    -------------------
    Failed example: list(foo)
    Expected: []
    Got:
        Undefined.__iter__
        []

    python-2.6.2-2.fc12
    ------------------------
    Failed example: list(foo)
    Expected: []
    Got:
        Undefined.__iter__
        __getattr__(('__length_hint__',))
        []

Since the Undefined class overloads sets __getattr__ = _die, this causes some unexpected behavior on Python 2.6.2

I'm thinking that this behavior was introduced in: http://bugs.python.org/issue1242657 Another example of this behavior can be found in the test case that came along with it: http://svn.python.org/view/python/trunk/Lib/test/test_iterlen.py?r1=69227&r2=69226&pathrev=69227

I threw together the following patch for Fedora that gets the test suite running again:

--- genshi/template/eval.py.orig	2009-09-11 17:09:13.589445262 -0400
+++ genshi/template/eval.py	2009-09-11 17:11:17.818691489 -0400
@@ -279,6 +279,10 @@
         raise UndefinedError(self._name, self._owner)
     __call__ = __getattr__ = __getitem__ = _die
 
+    # Hack around some behavior introduced in Python 2.6.2
+    # http://genshi.edgewall.org/ticket/324
+    __length_hint__ = None
+
 
 class LookupBase(object):
     """Abstract base class for variable lookup implementations."""

Changed 15 years ago by lmacken@…

python-genshi-0.5.1-py2.6.2-length_hint.patch

comment:2 Changed 14 years ago by cmlenz

  • Milestone changed from 0.6 to 0.6.1

comment:3 Changed 14 years ago by rblank

Another (much less elegant) patch is in comment:6:ticket:370.

comment:4 Changed 14 years ago by cmlenz

  • Milestone changed from 0.6.1 to 0.6
  • Status changed from new to assigned

Issue raised again in #370.

comment:5 Changed 14 years ago by cmlenz

  • Resolution set to fixed
  • Status changed from assigned to closed

Applied in [1101]. Thanks and sorry for the wait!

Note: See TracTickets for help on using tickets.