Test-Driven Development in Python
Subject:   Why the code failed
Date:   2005-03-30 19:33:11
From:   Gancho
Your code,

def matches(self, date):
return ((self.year and self.year == date.year or True) and
(self.month and self.month == date.month or True) and
( and == or True) and
(self.weekday and self.weekday == date.weekday() or True))

failed the testMatchesFalse test because == binds more tightly than "or."

>>> c=1
>>> c and c == 2 or True
>>> c and c == (2 or True)

I agree that the explicit code is cleaner.

I'm just learning Python, and it's interesting that laziness is one of the three virtues in the Perl world yet is decried in Python circles.

1 to 1 of 1
  1. Why the code failed
    2005-05-14 17:14:16  cpgray [View]

1 to 1 of 1