summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2017-05-23 11:05:37 +0200
committerXavier Morel <xmo@odoo.com>2017-06-26 16:45:03 +0200
commit5ee9ec7d6c5608ad75c63852557244ae65547c25 (patch)
tree672e8ae84e1168dc154f9aaf4093a17d4b2126c2
parentc5dcf75a813174ac5b27b4bc1fdeba1243e04347 (diff)
[FIX] P3: __nonzero__ -> __bool__
Also ~removed bool-testing on cursors
-rw-r--r--odoo/models.py6
-rw-r--r--odoo/sql_db.py12
2 files changed, 7 insertions, 11 deletions
diff --git a/odoo/models.py b/odoo/models.py
index 8adb0d9c7d8..8a44c40d006 100644
--- a/odoo/models.py
+++ b/odoo/models.py
@@ -169,8 +169,9 @@ class MetaModel(api.Meta):
class NewId(object):
""" Pseudo-ids for new records. """
- def __nonzero__(self):
+ def __bool__(self):
return False
+ __nonzero__ = __bool__
IdType = pycompat.integer_types + (str, unicode, NewId)
@@ -4501,9 +4502,10 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
# "Dunder" methods
#
- def __nonzero__(self):
+ def __bool__(self):
""" Test whether ``self`` is nonempty. """
return bool(getattr(self, '_ids', True))
+ __nonzero__ = __bool__
def __len__(self):
""" Return the size of ``self``. """
diff --git a/odoo/sql_db.py b/odoo/sql_db.py
index f2448259e10..81b717ef026 100644
--- a/odoo/sql_db.py
+++ b/odoo/sql_db.py
@@ -642,15 +642,9 @@ class Connection(object):
# serialized_cursor is deprecated - cursors are serialized by default
serialized_cursor = cursor
- def __nonzero__(self):
- """Check if connection is possible"""
- try:
- _logger.info("__nonzero__() is deprecated. (It is too expensive to test a connection.)")
- cr = self.cursor()
- cr.close()
- return True
- except Exception:
- return False
+ def __bool__(self):
+ raise NotImplementedError()
+ __nonzero__ = __bool__
def connection_info_for(db_or_uri):
""" parse the given `db_or_uri` and return a 2-tuple (dbname, connection_params)