Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
erp5 erp5
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Labels
    • Labels
  • Merge requests 143
    • Merge requests 143
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Environments
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Jobs
  • Commits
Collapse sidebar
  • nexedi
  • erp5erp5
  • Merge requests
  • !978

Merged
Created Nov 07, 2019 by Jérome Perrin@jeromeOwner

patches/pylint: fix regression with namedtuples

  • Overview 14
  • Commits 1
  • Pipelines 3
  • Changes 2

with namedtuples and unicode literals enabled, our patch break with:

Module py2stdlib, line 266, in infer_named_tuple
  ''' % {'name': name, 'fields': attributes})
Module Products.ERP5Type.patches.pylint, line 74, in string_build
  encoding = _guess_encoding(data)
Module astroid.builder, line 65, in _guess_encoding
  if string.startswith('\xef\xbb\xbf'):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)

because pylint/astroid uses string_build to evaluate the named tuple and the source code enabled unicode_literals future, string_build is called with an unicode object.

-> for inferred in node.func.infer():
  astroid-1.3.8-py2.7.egg/astroid/bases.py(391)infer()
-> return self._explicit_inference(self, context, **kwargs)
  astroid-1.3.8-py2.7.egg/astroid/brain/py2stdlib.py(266)infer_named_tuple()
-> ''' % {'name': name, 'fields': attributes})
> erp5/product/ERP5Type/patches/pylint.py(77)string_build()
-> data = data.encode('utf-8')
(Pdb) up
> astroid-1.3.8-py2.7.egg/astroid/brain/py2stdlib.py(266)infer_named_tuple()
-> ''' % {'name': name, 'fields': attributes})
(Pdb) l
249     def infer_named_tuple(node, context=None):
250         """Specific inference function for namedtuple CallFunc node"""
251         class_node, name, attributes = infer_func_form(node, nodes.Tuple._proxied,
252                                                        context=context)
253         fake = AstroidBuilder(MANAGER).string_build('''
254     class %(name)s(tuple):
255         _fields = %(fields)r
256         def _asdict(self):
257             return self.__dict__
258         @classmethod
259         def _make(cls, iterable, new=tuple.__new__, len=len):
260             return new(cls, iterable)
261         def _replace(_self, **kwds):
262             result = _self._make(map(kwds.pop, %(fields)r, _self))
263             if kwds:
264                 raise ValueError('Got unexpected field names: %%r' %% list(kwds))
265             return result
266  ->     ''' % {'name': name, 'fields': attributes})
(Pdb) pp name
u'NamedTuple'
(Pdb) pp attributes
[u'foo', u'bar']
(Pdb) pp [ (arg, arg.value) for arg in node.args ]
[(<Const(unicode) l.4 [checkPythonSourceCodelXOzr3] at 0x7f9f1caee250>,
  u'NamedTuple'),
 (<Const(unicode) l.4 [checkPythonSourceCodelXOzr3] at 0x7f9f1caeebd0>,
  u'foo bar')]
Assignee
Assign to
Reviewer
Request review from
None
Milestone
None
Assign milestone
Time tracking
Source branch: fix/pylint_guess_encoding
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7