Skip to content

Commit e38ebbd

Browse files
author
Nils Berg
committed
transforms: extend _locals instead of replacing it
this way we don't clobber existing locals, something that the new test demonstrates. previously, calls to save() and delete() on a model instance caused a pylint error.
1 parent 9acfea3 commit e38ebbd

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pylint_django/transforms/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def set_fake_locals(module):
2626
if module.name != package_name:
2727
return
2828
for class_name in class_names:
29-
module._locals[class_name] = fake._locals[class_name] # pylint: disable=protected-access
29+
module._locals[class_name].extend(fake._locals[class_name]) # pylint: disable=protected-access
3030

3131
MANAGER.register_transform(nodes.Module, set_fake_locals)
3232

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
Checks that Pylint does not complain about using Model and Manager methods
3+
"""
4+
# pylint: disable=C0111,W5101,W5103
5+
from django.db import models
6+
7+
8+
class SomeModel(models.Model):
9+
pass
10+
11+
if __name__ == '__main__':
12+
MODEL = SomeModel()
13+
MODEL.save()
14+
MODEL.delete()
15+
16+
COUNT = SomeModel.objects.count()

0 commit comments

Comments
 (0)