Skip to content

Commit d116bc4

Browse files
committed
[FIX] util/helpers: do not override docs in Python2
We cannot write to `__doc__` attributes of `namedtuple`s in Python2 ``` Python 2.7.18 (default, Oct 15 2023, 16:43:11) [GCC 11.4.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from collections import namedtuple >>> x = namedtuple("X", "x") >>> x.__doc__ = "x" Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: attribute '__doc__' of 'type' objects is not writable ``` closes #101 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent afa3e94 commit d116bc4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/util/helpers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
import logging
33
import os
4+
import sys
45
from collections import namedtuple
56

67
import lxml
@@ -218,15 +219,16 @@ def _get_theme_models():
218219

219220

220221
FieldsPathPart = namedtuple("FieldsPathPart", "field_model field_name relation_model")
221-
FieldsPathPart.__doc__ = """
222+
if sys.version_info[0] >= 3:
223+
FieldsPathPart.__doc__ = """
222224
Encapsulate information about a field within a fields path.
223225
224226
:param str field_model: model of the field
225227
:param str field_name: name of the field
226228
:param str relation_model: target model of the field, if relational, otherwise ``None``
227229
"""
228-
for _f in FieldsPathPart._fields:
229-
getattr(FieldsPathPart, _f).__doc__ = None
230+
for _f in FieldsPathPart._fields:
231+
getattr(FieldsPathPart, _f).__doc__ = None
230232

231233

232234
def resolve_model_fields_path(cr, model, path):

0 commit comments

Comments
 (0)