Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

New and simpler implementation of BooleanField

Ismael Carnales0cc289ac84cd
diff --git a/scrapy/contrib_exp/newitem/fields.py b/scrapy/contrib_exp/newitem/fields.py
index e0a47b593..7c82c83d4 100644
--- a/scrapy/contrib_exp/newitem/fields.py
+++ b/scrapy/contrib_exp/newitem/fields.py
@@ -51,11 +51,7 @@ class MultiValuedField(Field):
class BooleanField(Field):
def to_python(self, value):
- if value is None: return False
- if value in (True, False): return value
- if value in ('t', 'True', '1'): return True
- if value in ('f', 'False', '0'): return False
- raise FieldValueError("This value must be either True or False.")
+ return bool(value)
ansi_date_re = re.compile(r'^\d{4}-\d{1,2}-\d{1,2}$')