Skip to content

Commit c5b5bfd

Browse files
authored
Merge pull request #204 from PyCQA/201-fix-compat
Fix compatability with latest releases of astroid/pylint
2 parents 2ef6132 + a3c6ceb commit c5b5bfd

File tree

12 files changed

+71
-12
lines changed

12 files changed

+71
-12
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ matrix:
2727

2828
install:
2929
- pip install tox-travis
30+
- pip install -e .[for_tests]
3031
script:
3132
- |
3233
if [ -z "$SANITY_CHECK" ]; then

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
Version 2.0.3 (26 Nov 2018)
5+
---------------------------
6+
7+
- Fixing compatability between ranges of astroid (2.0.4 -> 2.1) and pylint (2.1.1 -> 2.2)
8+
`#201 <https://github.com/PyCQA/pylint-django/issues/201>` and `#202 <https://github.com/PyCQA/pylint-django/issues/202>`
9+
410
Version 2.0.2 (26 Aug 2018)
511
---------------------------
612

pylint_django/augmentations/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,14 @@ def is_wsgi_application(node):
745745
(frame.name == 'wsgi' or frame.path[0].endswith('wsgi.py') or frame.file.endswith('wsgi.py'))
746746

747747

748+
# Compat helpers
749+
def pylint_newstyle_classdef_compat(linter, warning_name, augment):
750+
if not hasattr(NewStyleConflictChecker, 'visit_classdef'):
751+
return
752+
suppress_message(linter, getattr(NewStyleConflictChecker, 'visit_classdef'), warning_name, augment)
753+
754+
755+
# augment things
748756
def apply_augmentations(linter):
749757
"""Apply augmentation and suppression rules."""
750758
augment_visit(linter, TypeChecker.visit_attribute, foreign_key_sets)
@@ -787,15 +795,15 @@ def apply_augmentations(linter):
787795

788796
# Meta
789797
suppress_message(linter, DocStringChecker.visit_classdef, 'missing-docstring', is_model_meta_subclass)
790-
suppress_message(linter, NewStyleConflictChecker.visit_classdef, 'old-style-class', is_model_meta_subclass)
798+
pylint_newstyle_classdef_compat(linter, 'old-style-class', is_model_meta_subclass)
791799
suppress_message(linter, ClassChecker.visit_classdef, 'no-init', is_model_meta_subclass)
792800
suppress_message(linter, MisdesignChecker.leave_classdef, 'too-few-public-methods', is_model_meta_subclass)
793801
suppress_message(linter, ClassChecker.visit_attribute, 'protected-access', allow_meta_protected_access)
794802

795803
# Media
796804
suppress_message(linter, NameChecker.visit_assignname, 'C0103', is_model_media_valid_attributes)
797805
suppress_message(linter, DocStringChecker.visit_classdef, 'missing-docstring', is_model_media_subclass)
798-
suppress_message(linter, NewStyleConflictChecker.visit_classdef, 'old-style-class', is_model_media_subclass)
806+
pylint_newstyle_classdef_compat(linter, 'old-style-class', is_model_media_subclass)
799807
suppress_message(linter, ClassChecker.visit_classdef, 'no-init', is_model_media_subclass)
800808
suppress_message(linter, MisdesignChecker.leave_classdef, 'too-few-public-methods', is_model_media_subclass)
801809

@@ -823,7 +831,7 @@ def apply_augmentations(linter):
823831

824832
# django-mptt
825833
suppress_message(linter, DocStringChecker.visit_classdef, 'missing-docstring', is_model_mpttmeta_subclass)
826-
suppress_message(linter, NewStyleConflictChecker.visit_classdef, 'old-style-class', is_model_mpttmeta_subclass)
834+
pylint_newstyle_classdef_compat(linter, 'old-style-class', is_model_mpttmeta_subclass)
827835
suppress_message(linter, ClassChecker.visit_classdef, 'W0232', is_model_mpttmeta_subclass)
828836
suppress_message(linter, MisdesignChecker.leave_classdef, 'too-few-public-methods', is_model_mpttmeta_subclass)
829837

pylint_django/checkers/forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def _get_child_meta(node):
1313
for child in node.get_children():
1414
if isinstance(child, ClassDef) and child.name == 'Meta':
1515
return child
16+
return None
1617

1718

1819
class FormChecker(BaseChecker):

pylint_django/checkers/json_response.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
import astroid
1010

11-
from pylint import interfaces
12-
from pylint import checkers
11+
from pylint import interfaces, checkers
1312
from pylint.checkers import utils
1413
from pylint_django.__pkginfo__ import BASE_ID
1514

pylint_django/compat.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# flake8: noqa
2+
# pylint: skip-file
3+
# no sane linter can figure out the hackiness in this compatability layer...
4+
5+
try:
6+
from astroid.nodes import ClassDef, FunctionDef, ImportFrom, AssignName, Attribute
7+
except ImportError:
8+
from astroid.nodes import (
9+
Class as ClassDef,
10+
Function as FunctionDef,
11+
From as ImportFrom,
12+
AssName as AssignName,
13+
Getattr as Attribute,
14+
)
15+
16+
try:
17+
from astroid.bases import YES as Uninferable
18+
except ImportError:
19+
try:
20+
from astroid.util import YES as Uninferable
21+
except ImportError:
22+
from astroid.util import Uninferable
23+
24+
try:
25+
django = __import__("django")
26+
django_version = django.VERSION
27+
except ImportError:
28+
# if not available, will be handled by the django_installed checker
29+
django_version = (1, 5)
30+
31+
32+
def inferred(node):
33+
if hasattr(node, "inferred"):
34+
return node.inferred
35+
else:
36+
return node.infered
37+
38+
39+
def instantiate_class(node):
40+
if hasattr(node, "instantiate_class"):
41+
return node.instantiate_class
42+
else:
43+
return node.instanciate_class

pylint_django/tests/input/func_noerror_test_wsgi_request.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
class SomeModel(models.Model):
1111
"""Just a model."""
12-
pass
1312

1413

1514
class SomeTestCase(TestCase):

pylint_django/transforms/transforms/django_db_models_fields_files.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=super-init-not-called
12
from django.db.models.fields import files as django_fields
23

34

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
def ugettext_lazy(x):
1+
def ugettext_lazy(_):
22
return ''

pylint_django/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Utils."""
22
import sys
33

4-
from astroid.util import YES
54
from astroid.bases import Instance
6-
from astroid.nodes import ClassDef
75
from astroid.exceptions import InferenceError
6+
from astroid.nodes import ClassDef
87

8+
from pylint_django.compat import Uninferable
99

1010
PY3 = sys.version_info >= (3, 0)
1111

@@ -15,7 +15,7 @@ def node_is_subclass(cls, *subclass_names):
1515
if not isinstance(cls, (ClassDef, Instance)):
1616
return False
1717

18-
if cls.bases == YES:
18+
if cls.bases == Uninferable:
1919
return False
2020
for base_cls in cls.bases:
2121
try:

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
author_email='code@landscape.io',
1414
description='A Pylint plugin to help Pylint understand the Django web framework',
1515
long_description=LONG_DESCRIPTION,
16-
version='2.0.2',
16+
version='2.0.3',
1717
packages=find_packages(),
1818
include_package_data=True,
1919
install_requires=[
@@ -22,6 +22,7 @@
2222
],
2323
extras_require={
2424
'with_django': ['Django'],
25+
'for_tests': ['django_tables2', 'factory-boy'],
2526
},
2627
license='GPLv2',
2728
classifiers=[

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ commands =
1616
django_not_installed: bash -c \'pylint --load-plugins=pylint_django setup.py | grep django-not-available\'
1717
django_is_installed: pylint --load-plugins=pylint_django setup.py
1818
flake8: flake8
19-
pylint: pylint --rcfile=tox.ini -d missing-docstring --ignore=tests pylint_django setup
19+
pylint: pylint --rcfile=tox.ini -d missing-docstring,too-many-branches,too-many-return-statements,too-many-ancestors,fixme --ignore=tests pylint_django setup
2020
readme: python setup.py check --restructuredtext --strict
2121
py{36}-django{111,20}: coverage run pylint_django/tests/test_func.py -v
2222
py{35,36,37}-django21: coverage run pylint_django/tests/test_func.py -v

0 commit comments

Comments
 (0)