diff options
| author | Adrian Torres <adt@odoo.com> | 2018-11-08 15:27:30 +0000 |
|---|---|---|
| committer | Adrian Torres <adt@odoo.com> | 2018-11-29 09:28:17 +0000 |
| commit | 52f5528cfb6d1152ee226e268247dc685a8ba329 (patch) | |
| tree | b44ecfa477b50dd3e488f09f623eecc8bc8e9d7d /odoo/osv | |
| parent | e5c864a596b72515837f0ed1e07550398ecc1ab0 (diff) | |
[REF] *: replace deprecated pycompat helpers for builtins
This commit replaces calls to pycompat helpers that were intended for
python 2 <-> python 3 interoperability for python 3 builtins, as python
2 is no longer officially supported by Odoo.
This includes:
* calls to imap/izip/ifilter replaced by map/zip/filter
* uses of text_type replaced by str
* uses of unichr replaced by chr
* calls to implements_to_string, implements_iterator removed
* string_types and integer_types replaced by str, int respectively
* calls to to_native replaced by calls to to_text
This is done in preparation to the removal of these deprecated helpers
in the following commit.
Diffstat (limited to 'odoo/osv')
| -rw-r--r-- | odoo/osv/expression.py | 22 | ||||
| -rw-r--r-- | odoo/osv/orm.py | 3 |
2 files changed, 12 insertions, 13 deletions
diff --git a/odoo/osv/expression.py b/odoo/osv/expression.py index 483f325322c..1eecceeca6c 100644 --- a/odoo/osv/expression.py +++ b/odoo/osv/expression.py @@ -403,7 +403,7 @@ def normalize_leaf(element): def is_operator(element): """ Test whether an object is a valid domain operator. """ - return isinstance(element, pycompat.string_types) and element in DOMAIN_OPERATORS + return isinstance(element, str) and element in DOMAIN_OPERATORS def is_leaf(element, internal=False): @@ -424,7 +424,7 @@ def is_leaf(element, internal=False): return (isinstance(element, tuple) or isinstance(element, list)) \ and len(element) == 3 \ and element[1] in INTERNAL_OPS \ - and ((isinstance(element[0], pycompat.string_types) and element[0]) + and ((isinstance(element[0], str) and element[0]) or tuple(element) in (TRUE_LEAF, FALSE_LEAF)) @@ -723,11 +723,11 @@ class expression(object): return the list of related ids """ names = [] - if isinstance(value, pycompat.string_types): + if isinstance(value, str): names = [value] - elif value and isinstance(value, (tuple, list)) and all(isinstance(item, pycompat.string_types) for item in value): + elif value and isinstance(value, (tuple, list)) and all(isinstance(item, str) for item in value): names = value - elif isinstance(value, pycompat.integer_types): + elif isinstance(value, int): if not value: # given this nonsensical domain, it is generally cheaper to # interpret False as [], so that "X child_of False" will @@ -955,7 +955,7 @@ class expression(object): if right is not False: # determine ids2 in comodel - if isinstance(right, pycompat.string_types): + if isinstance(right, str): op2 = (TERM_OPERATORS_NEGATION[operator] if operator in NEGATIVE_TERM_OPERATORS else operator) ids2 = [x[0] for x in comodel.name_search(right, domain or [], op2, limit=None)] @@ -1012,7 +1012,7 @@ class expression(object): elif right is not False: # determine ids2 in comodel - if isinstance(right, pycompat.string_types): + if isinstance(right, str): domain = field.domain if callable(domain): domain = domain(model) @@ -1064,8 +1064,8 @@ class expression(object): res_ids.append(False) # TODO this should not be appended if False was in 'right' return left, 'in', res_ids # resolve string-based m2o criterion into IDs - if isinstance(right, pycompat.string_types) or \ - right and isinstance(right, (tuple, list)) and all(isinstance(item, pycompat.string_types) for item in right): + if isinstance(right, str) or \ + right and isinstance(right, (tuple, list)) and all(isinstance(item, str) for item in right): push(create_substitution_leaf(leaf, _get_expression(comodel, left, right, operator), model)) else: # right == [] or right == False and all other cases are handled by __leaf_to_sql() @@ -1097,7 +1097,7 @@ class expression(object): else: if field.type == 'datetime' and right: - if isinstance(right, pycompat.string_types) and len(right) == 10: + if isinstance(right, str) and len(right) == 10: if operator in ('>', '<='): right += ' 23:59:59' else: @@ -1267,7 +1267,7 @@ class expression(object): query = '(%s %s %s)' % (unaccent(column + cast), sql_operator, unaccent(format)) if need_wildcard: - native_str = pycompat.to_native(right) + native_str = pycompat.to_text(right) if not native_str: query = '(%s OR %s."%s" IS NULL)' % (query, table_alias, left) params = ['%%%s%%' % native_str] diff --git a/odoo/osv/orm.py b/odoo/osv/orm.py index 0d5c7e66fb1..e316949dae1 100644 --- a/odoo/osv/orm.py +++ b/odoo/osv/orm.py @@ -3,7 +3,6 @@ import warnings from lxml import etree -from odoo.tools import pycompat from ..exceptions import except_orm from ..models import ( MetaModel, @@ -125,7 +124,7 @@ def setup_modifiers(node, field=None, context=None, in_tree_view=False): def test_modifiers(what, expected): modifiers = {} - if isinstance(what, pycompat.string_types): + if isinstance(what, str): node = etree.fromstring(what) transfer_node_to_modifiers(node, modifiers) simplify_modifiers(modifiers) |
