Skip to content
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

inconsistent-mro , but Python does not raise error #1377

Closed
pierluca opened this issue Mar 14, 2017 · 4 comments
Closed

inconsistent-mro , but Python does not raise error #1377

pierluca opened this issue Mar 14, 2017 · 4 comments
Labels

Comments

@pierluca
Copy link

Steps to reproduce

  1. pip install autobahn[twisted]
  2. Try linting the following code:
from twisted.internet.protocol import ReconnectingClientFactory
from autobahn.twisted import websocket


class RetryFactory(websocket.WampWebSocketClientFactory,
                   ReconnectingClientFactory):
    pass

Current behavior

poc.py:5: [R0901(too-many-ancestors), RetryFactory] Too many ancestors (11/7)
poc.py:5: [E0240(inconsistent-mro), RetryFactory] Inconsistent method resolution order for class 'RetryFactory'

Expected behavior

poc.py:5: [R0901(too-many-ancestors), RetryFactory] Too many ancestors (11/7)

Too many ancestors is expected, given the library imports at hand.
However, we can't reproduce the inconsistent method resolution order on a Python execution of the script. Isn't this a false positive?

pylint --version output

pylint 1.6.5, 
astroid 1.4.9
Python 2.7.9 (default, Jun 29 2016, 13:08:31) 
[GCC 4.9.2]
@PCManticore
Copy link
Contributor

It might be a false positive. We are trying to compute the MRO, but we might have some edge cases we didn't handle properly when we first implemented the algorithm. Thank you, will take a look.

@rogalski
Copy link
Contributor

rogalski commented Apr 2, 2017

There is a magic decorator in twisted source that converts old-style class to new-style classes in runtime. Most likely Pylint still sees this class as old-style class, which changes the way MRO works. Our C3 algorithm implementation looks fine to be honest.

@rogalski
Copy link
Contributor

rogalski commented Apr 2, 2017

class Factory(object):  # make it old-style class to trigger an error
    pass


class ClientFactory(Factory):
    pass


class ReconnectingClientFactory(ClientFactory):
    pass


class WebSocketAdapterFactory(object):
    pass


class WebSocketClientFactory(WebSocketAdapterFactory, ClientFactory):
    pass


class WampWebSocketClientFactory(WebSocketClientFactory):
    pass


class RetryFactory(WampWebSocketClientFactory, ReconnectingClientFactory):
    pass

Slightly smaller, standalone reproduction.

@PCManticore
Copy link
Contributor

Closed in astroid's master by pylint-dev/astroid@5092504

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants