Commit 5b5728a7 authored by Jérome Perrin's avatar Jérome Perrin

patches/pylint: fix regression with namedtuples

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)
parent 3d8f2a5a
Pipeline #6571 failed with stage
in 0 seconds
......@@ -70,6 +70,10 @@ def string_build(self, data, modname='', path=None):
module.file_bytes = data.encode('utf-8')
return self._post_build(module, 'utf-8')
"""
if isinstance(data, unicode):
# when used internally, like when inferring namedtuples, this can be called
# with unicode.
data = data.encode('utf-8')
encoding = _guess_encoding(data)
if encoding is None:
# Encoding not defined in the source file, assuming utf-8...
......
......@@ -2308,6 +2308,20 @@ undefined()
imported_module2_with_version])
self.assertEqual(component.getTextContentWarningMessageList(), [])
def testPylintNamedtupleUnicodeLiteralsRegression(self):
# regression for a bug with our pylint patches on guess encoding
# a named tuple with unicode_literals enabled cause UnicodeDecodeError
component = self._newComponent(
self._generateReference('TestPylintNamedtupleUnicodeLiteralsRegression'))
component.setTextContent("""
from __future__ import unicode_literals
from collections import namedtuple
namedtuple('NamedTuple', 'foo bar')(1, 2)
""")
self.tic()
self.assertEqual(component.getTextContentWarningMessageList(), [])
self.assertEqual(component.getTextContentErrorMessageList(), [])
from Products.ERP5Type.Core.ExtensionComponent import ExtensionComponent
class TestZodbExtensionComponent(_TestZodbComponent):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment