pylint-dev / pylint-plugin-utils

Utilities and helpers for writing Pylint plugins
GNU General Public License v2.0
24 stars 12 forks source link

Does not work with python3 #1

Closed lhupfeldt closed 10 years ago

lhupfeldt commented 10 years ago

Hi,

Python3 does not have the im_class attribute. I've implemented a (backwards compatible) fix to make it work with python3. I tried it with the pylint_django plugin.

---- init.py ---

...

def get_class(module_name, kls):
    parts = kls.split('.')
    m = __import__(module_name)
    for mp in module_name.split('.')[1:]:
        m = getattr(m, mp)
    klass = getattr(m, parts[0])
    return klass

def augment_visit(linter, checker_method, augmentation):
...
    try:
        checker = get_checker(linter, checker_method.im_class)
    except AttributeError:
        try:
            checker = get_checker(linter, checker_method.__self__.__class__)
        except AttributeError:
            checker = get_checker(linter, get_class(checker_method.__module__, checker_method.__qualname__))
....
carlio commented 10 years ago

Thanks for the help - I have "merged" this in now, and version 0.1.1 includes it. I'll work on updating @landscapeio/pylint-django as well.

lhupfeldt commented 10 years ago

Thank you for making the plugin!

Regards / Venlig Hilsen Lars Hupfeldt Nielsen Hupfeldt IT

Phone: +45 2060 3546

2014/1/25 carlio notifications@github.com

Thanks for the help - I have "merged" this in now, and version 0.1.1includes it. I'll work on updating @landscapeio/pylint-django as well.

— Reply to this email directly or view it on GitHubhttps://github.com/landscapeio/pylint-plugin-utils/issues/1#issuecomment-33288698 .