Skip to content

1.8.4: pylint/test/acceptance/test_stdlib.py failures #2080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sandrotosi opened this issue May 14, 2018 · 1 comment
Closed

1.8.4: pylint/test/acceptance/test_stdlib.py failures #2080

sandrotosi opened this issue May 14, 2018 · 1 comment

Comments

@sandrotosi
Copy link
Contributor

Hello,
with the recent release of pylint 1.8.4, pylint/test/acceptance/test_stdlib.py fails every single test under python 2.7, with lines like:

________________________ test_libmodule[collections.py] ________________________

test_module_location = '/usr/lib/python2.7', test_module_name = 'collections.py'

    @pytest.mark.acceptance
    @pytest.mark.parametrize(("test_module_location", "test_module_name"),
                             MODULES_TO_CHECK, ids=MODULES_NAMES)
    def test_libmodule(test_module_location, test_module_name):
        os.chdir(test_module_location)
        with _patch_stdout(io.StringIO()):
            try:
>               pylint.lint.Run([test_module_name, '--enable=all'])

/build/pylint-1.8.4/pylint/test/acceptance/test_stdlib.py:46: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/build/pylint-1.8.4/pylint/lint.py:1347: in __init__
    linter.check(args)
/build/pylint-1.8.4/pylint/lint.py:768: in check
    self._do_check(files_or_modules)
/build/pylint-1.8.4/pylint/lint.py:901: in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
/build/pylint-1.8.4/pylint/lint.py:978: in check_astroid_module
    checker.process_tokens(tokens)
/build/pylint-1.8.4/pylint/checkers/format.py:852: in process_tokens
    handler(tokens, idx)
/build/pylint-1.8.4/pylint/checkers/format.py:694: in _check_surrounded_by_space
    self._check_space(tokens, i, (_MUST, _MUST))
/build/pylint-1.8.4/pylint/checkers/format.py:742: in _check_space
    _underline_token(token)))
/build/pylint-1.8.4/pylint/checkers/__init__.py:98: in add_message
    self.linter.add_message(msg_id, line, node, args, confidence)
/build/pylint-1.8.4/pylint/utils.py:443: in add_message
    (abspath, path, module, obj, line or 1, col_offset or 0), msg, confidence))
/build/pylint-1.8.4/pylint/reporters/text.py:145: in handle_message
    self.writeln('************* Module %s' % msg.module)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pylint.reporters.text.TextReporter object at 0x7f05735e09d0>
string = '************* Module collections'

    def writeln(self, string=''):
        """write a line in the output buffer"""
>       print(self.encode(string), file=self.out)
E       TypeError: unicode argument expected, got 'str'

/build/pylint-1.8.4/pylint/reporters/__init__.py:83: TypeError

while the only failure when running the test suite on python3.6 is:

=================================== FAILURES ===================================
___________________ test_functional[deprecated_module_py36] ____________________

test_file = <test_functional.FunctionalTestFile object at 0x7f644d448b00>

    @pytest.mark.parametrize("test_file", TESTS, ids=TESTS_NAMES)
    def test_functional(test_file):
        LintTest = LintModuleOutputUpdate(test_file) if UPDATE else LintModuleTest(test_file)
        LintTest.setUp()
>       LintTest._runTest()

pylint/test/test_functional.py:377: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <test_functional.LintModuleTest object at 0x7f644a5a14a8>

    def _runTest(self):
        self._linter.check([self._test_file.module])
    
        expected_messages, expected_text = self._get_expected()
        received_messages, received_text = self._get_received()
    
        if expected_messages != received_messages:
            msg = ['Wrong results for file "%s":' % (self._test_file.base)]
            missing, unexpected = multiset_difference(expected_messages,
                                                      received_messages)
            if missing:
                msg.append('\nExpected in testdata:')
                msg.extend(' %3d: %s' % msg for msg in sorted(missing))
            if unexpected:
                msg.append('\nUnexpected in testdata:')
                msg.extend(' %3d: %s' % msg for msg in sorted(unexpected))
>           pytest.fail('\n'.join(msg))
E           Failed: Wrong results for file "deprecated_module_py36":
E           
E           Unexpected in testdata:
E              5: import-error

pylint/test/test_functional.py:321: Failed
----------------------------- Captured stderr call -----------------------------
Using config file /build/pylint-1.8.4/pylint/test/functional/deprecated_module_py36.rc
___________________________ test_libmodule[enum.py] ____________________________

self = <Instance of enum.EnumMeta at 0x140068555045800>, name = '__init__'
context = <astroid.context.InferenceContext object at 0x7f644582cc28>
lookupclass = False

    def getattr(self, name, context=None, lookupclass=True):
        try:
>           values = self._proxied.instance_attr(name, context)

../python3/dist-packages/astroid/bases.py:135: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ClassDef.EnumMeta l.112 at 0x7f64419d1f28>, name = '__init__'
context = <astroid.context.InferenceContext object at 0x7f644582cc28>

    def instance_attr(self, name, context=None):
        """Get the list of nodes associated to the given attribute name.
    
            Assignments are looked for in both this class and in parents.
    
            :returns: The list of assignments to the given name.
            :rtype: list(NodeNG)
    
            :raises AttributeInferenceError: If no attribute with this name
                can be found in this class or parent classes.
            """
        # Return a copy, so we don't modify self.instance_attrs,
        # which could lead to infinite loop.
        values = list(self.instance_attrs.get(name, []))
        # get all values from parents
        for class_node in self.instance_attr_ancestors(name, context):
            values += class_node.instance_attrs[name]
        values = [n for n in values if not isinstance(n, node_classes.DelAttr)]
        if values:
            return values
        raise exceptions.AttributeInferenceError(target=self, attribute=name,
>                                                context=context)
E       astroid.exceptions.AttributeInferenceError: '__init__' not found on <ClassDef.EnumMeta l.112 at 0x7f64419d1f28>.

../python3/dist-packages/astroid/scoped_nodes.py:2164: AttributeInferenceError

During handling of the above exception, another exception occurred:

self = <Instance of enum.EnumMeta at 0x140068555045800>, name = '__init__'
context = <astroid.context.InferenceContext object at 0x7f644582cc28>

    def igetattr(self, name, context=None):
        """inferred getattr"""
        if not context:
            context = contextmod.InferenceContext()
        try:
            # avoid recursively inferring the same attr on the same class
            if context.push((self._proxied, name)):
                return
    
            # XXX frame should be self._proxied, or not ?
>           get_attr = self.getattr(name, context, lookupclass=False)

../python3/dist-packages/astroid/bases.py:169: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Instance of enum.EnumMeta at 0x140068555045800>, name = '__init__'
context = <astroid.context.InferenceContext object at 0x7f644582cc28>
lookupclass = False

    def getattr(self, name, context=None, lookupclass=True):
        try:
            values = self._proxied.instance_attr(name, context)
        except exceptions.AttributeInferenceError:
            if self.special_attributes and name in self.special_attributes:
                return [self.special_attributes.lookup(name)]
    
            if lookupclass:
                # Class attributes not available through the instance
                # unless they are explicitly defined.
                return self._proxied.getattr(name, context,
                                             class_context=False)
    
            util.reraise(exceptions.AttributeInferenceError(target=self,
                                                            attribute=name,
>                                                           context=context))

../python3/dist-packages/astroid/bases.py:148: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

exception = AttributeInferenceError('{attribute!r} not found on {target!r}.',)

    def reraise(exception):
        '''Reraises an exception with the traceback from the current exception
        block.'''
>       six.reraise(type(exception), exception, sys.exc_info()[2])

../python3/dist-packages/astroid/util.py:30: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

tp = <class 'astroid.exceptions.AttributeInferenceError'>, value = None
tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)

../python3/dist-packages/six.py:692: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Instance of enum.EnumMeta at 0x140068555045800>, name = '__init__'
context = <astroid.context.InferenceContext object at 0x7f644582cc28>
lookupclass = False

    def getattr(self, name, context=None, lookupclass=True):
        try:
>           values = self._proxied.instance_attr(name, context)

../python3/dist-packages/astroid/bases.py:135: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ClassDef.EnumMeta l.112 at 0x7f64419d1f28>, name = '__init__'
context = <astroid.context.InferenceContext object at 0x7f644582cc28>

    def instance_attr(self, name, context=None):
        """Get the list of nodes associated to the given attribute name.
    
            Assignments are looked for in both this class and in parents.
    
            :returns: The list of assignments to the given name.
            :rtype: list(NodeNG)
    
            :raises AttributeInferenceError: If no attribute with this name
                can be found in this class or parent classes.
            """
        # Return a copy, so we don't modify self.instance_attrs,
        # which could lead to infinite loop.
        values = list(self.instance_attrs.get(name, []))
        # get all values from parents
        for class_node in self.instance_attr_ancestors(name, context):
            values += class_node.instance_attrs[name]
        values = [n for n in values if not isinstance(n, node_classes.DelAttr)]
        if values:
            return values
        raise exceptions.AttributeInferenceError(target=self, attribute=name,
>                                                context=context)
E       astroid.exceptions.AttributeInferenceError: '__init__' not found on <Instance of enum.EnumMeta at 0x140068555045800>.

../python3/dist-packages/astroid/scoped_nodes.py:2164: AttributeInferenceError

During handling of the above exception, another exception occurred:

test_module_location = '/usr/lib/python3.6', test_module_name = 'enum.py'

    @pytest.mark.acceptance
    @pytest.mark.parametrize(("test_module_location", "test_module_name"),
                             MODULES_TO_CHECK, ids=MODULES_NAMES)
    def test_libmodule(test_module_location, test_module_name):
        os.chdir(test_module_location)
        with _patch_stdout(io.StringIO()):
            try:
>               pylint.lint.Run([test_module_name, '--enable=all'])

/build/pylint-1.8.4/pylint/test/acceptance/test_stdlib.py:46: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/build/pylint-1.8.4/pylint/lint.py:1347: in __init__
    linter.check(args)
/build/pylint-1.8.4/pylint/lint.py:768: in check
    self._do_check(files_or_modules)
/build/pylint-1.8.4/pylint/lint.py:901: in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
/build/pylint-1.8.4/pylint/lint.py:980: in check_astroid_module
    walker.walk(ast_node)
/build/pylint-1.8.4/pylint/utils.py:1014: in walk
    self.walk(child)
/build/pylint-1.8.4/pylint/utils.py:1014: in walk
    self.walk(child)
/build/pylint-1.8.4/pylint/utils.py:1014: in walk
    self.walk(child)
/build/pylint-1.8.4/pylint/utils.py:1014: in walk
    self.walk(child)
/build/pylint-1.8.4/pylint/utils.py:1014: in walk
    self.walk(child)
/build/pylint-1.8.4/pylint/utils.py:1011: in walk
    cb(astroid)
/build/pylint-1.8.4/pylint/checkers/refactoring.py:361: in visit_call
    self._check_raising_stopiteration_in_generator_next_call(node)
/build/pylint-1.8.4/pylint/checkers/refactoring.py:365: in _check_raising_stopiteration_in_generator_next_call
    inferred = utils.safe_infer(node.func)
/build/pylint-1.8.4/pylint/checkers/utils.py:824: in safe_infer
    next(inferit)
../python3/dist-packages/astroid/decorators.py:89: in wrapped
    res = next(generator)
../python3/dist-packages/astroid/decorators.py:142: in raise_if_nothing_inferred
    yield next(generator)
../python3/dist-packages/astroid/inference.py:259: in infer_attribute
    for obj in owner.igetattr(self.attrname, context):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Instance of enum.EnumMeta at 0x140068555045800>, name = '__init__'
context = <astroid.context.InferenceContext object at 0x7f644582cc28>

    def igetattr(self, name, context=None):
        """inferred getattr"""
        if not context:
            context = contextmod.InferenceContext()
        try:
            # avoid recursively inferring the same attr on the same class
            if context.push((self._proxied, name)):
                return
    
            # XXX frame should be self._proxied, or not ?
            get_attr = self.getattr(name, context, lookupclass=False)
            for stmt in _infer_stmts(self._wrap_attr(get_attr, context),
                                     context, frame=self):
                yield stmt
        except exceptions.AttributeInferenceError:
            try:
                # fallback to class.igetattr since it has some logic to handle
                # descriptors
>               attrs = self._proxied.igetattr(name, context, class_context=False)
E               TypeError: igetattr() got an unexpected keyword argument 'class_context'

../python3/dist-packages/astroid/bases.py:177: TypeError
----------------------------- Captured stderr call -----------------------------
No config file found, using default configuration
============================== 1 tests deselected ==============================
======= 2 failed, 785 passed, 37 skipped, 1 deselected in 220.12 seconds =======
PCManticore added a commit that referenced this issue May 26, 2018
PCManticore added a commit that referenced this issue May 26, 2018
PCManticore added a commit that referenced this issue May 26, 2018
@PCManticore
Copy link
Contributor

Thanks @sandrotosi ! I think this is fixed now:

  • for the Python 3.6 failure, the linked commit should fix the problem for both master & 1.9 version
  • the astroid TypeError should be fixed by pylint-dev/astroid@2539038, for both astroid's master and astroid 1.6 (when we'll release it)
  • the AttributeInferenceError should also be fixed by that commit
  • The TypeError: unicode argument expected should be fixed by 20acde4

sushobhit27 pushed a commit to sushobhit27/pylint that referenced this issue Jun 8, 2018
brycepg pushed a commit to brycepg/pylint that referenced this issue Jun 14, 2018
In some cases the _proxied object points to another Instance, not to the
Class of an Instance node (usually this happens with enum and with our hardcoded inference support
for this library). Instead of getting a TypeError, we check before if the _proxied matches
what we expect.

Found by pylint-dev#2080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants