Skip to content

Commit 4e33e90

Browse files
authored
Merge pull request #348 from dineshtrivedi/276
276 - Fixing Macos AttributeError: Can't pickle local object
2 parents f43c8bd + e0905e2 commit 4e33e90

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

CONTRIBUTORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
* [michael-k](https://github.com/michael-k)
2020
* [naquiroz](https://github.com/naquiroz)
2121
* [john-sandall](https://github.com/john-sandall)
22+
* [dineshtrivedi](https://github.com/dineshtrivedi)

pylint_django/augmentations/__init__.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,13 @@ def is_model_test_case_subclass(node):
645645
return node_is_subclass(node, "django.test.testcases.TestCase")
646646

647647

648-
def generic_is_view_attribute(parents, attrs):
649-
"""Generates is_X_attribute function for given parents and attrs."""
648+
class IsAttribute:
649+
def __init__(self, parents, attrs):
650+
self.parents = parents
651+
self.attrs = attrs
650652

651-
def is_attribute(node):
652-
return _attribute_is_magic(node, attrs, parents)
653-
654-
return is_attribute
653+
def __call__(self, node):
654+
return _attribute_is_magic(node, self.attrs, self.parents)
655655

656656

657657
def is_model_view_subclass_method_shouldnt_be_function(node):
@@ -756,9 +756,12 @@ def allow_meta_protected_access(node):
756756
return False
757757

758758

759-
def is_class(class_name):
760-
"""Shortcut for node_is_subclass."""
761-
return lambda node: node_is_subclass(node, class_name)
759+
class IsClass:
760+
def __init__(self, class_name):
761+
self.class_name = class_name
762+
763+
def __call__(self, node):
764+
return node_is_subclass(node, self.class_name)
762765

763766

764767
def wrap(orig_method, with_method):
@@ -858,37 +861,37 @@ def apply_augmentations(linter):
858861
linter,
859862
TypeChecker.visit_attribute,
860863
"no-member",
861-
generic_is_view_attribute(parents, attrs),
864+
IsAttribute(parents, attrs),
862865
)
863866

864867
# formviews have too many ancestors, there's nothing the user of the library can do about that
865868
suppress_message(
866869
linter,
867870
MisdesignChecker.visit_classdef,
868871
"too-many-ancestors",
869-
is_class("django.views.generic.edit.FormView"),
872+
IsClass("django.views.generic.edit.FormView"),
870873
)
871874

872875
# class-based generic views just have a longer inheritance chain
873876
suppress_message(
874877
linter,
875878
MisdesignChecker.visit_classdef,
876879
"too-many-ancestors",
877-
is_class("django.views.generic.detail.BaseDetailView"),
880+
IsClass("django.views.generic.detail.BaseDetailView"),
878881
)
879882
suppress_message(
880883
linter,
881884
MisdesignChecker.visit_classdef,
882885
"too-many-ancestors",
883-
is_class("django.views.generic.edit.ProcessFormView"),
886+
IsClass("django.views.generic.edit.ProcessFormView"),
884887
)
885888

886889
# model forms have no __init__ method anywhere in their bases
887890
suppress_message(
888891
linter,
889892
ClassChecker.visit_classdef,
890893
"W0232",
891-
is_class("django.forms.models.ModelForm"),
894+
IsClass("django.forms.models.ModelForm"),
892895
)
893896

894897
# Meta

pylint_django/tests/test_func.py

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import csv
22
import os
3+
import pickle
34
import sys
45

56
import pylint
@@ -112,5 +113,15 @@ def test_migrations_plugin(test_file):
112113
LintTest._runTest()
113114

114115

116+
@pytest.mark.parametrize("test_file", MIGRATIONS_TESTS[:1], ids=MIGRATIONS_TESTS_NAMES[:1])
117+
def test_linter_should_be_pickleable_with_pylint_djang_plugin_installed(test_file):
118+
LintTest = PylintDjangoMigrationsTest(test_file)
119+
LintTest.setUp()
120+
121+
# LintModuleTest sets reporter to instance of FunctionalTestReporter that is not picklable
122+
LintTest._linter.reporter = None
123+
pickle.dumps(LintTest._linter)
124+
125+
115126
if __name__ == "__main__":
116127
sys.exit(pytest.main(sys.argv))

0 commit comments

Comments
 (0)