Skip to content

Commit 7b44aa1

Browse files
imomalievatodorov
authored andcommitted
fix lint errors
1 parent 934eb65 commit 7b44aa1

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

CHANGELOG.rst

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

4-
Version 2.0.8 (18 April 2019)
4+
Version 2.0.9 (dev)
55
-----------------------------
66

7-
- Fix `UnboundLocalError: local variable 'key_cls' referenced before assignment`` for FK when using ``to`` as string pointing to model when models is a package
7+
- Fix ``UnboundLocalError: local variable 'key_cls' referenced before assignment`` for FK when using ``to`` as string pointing to model when models is a package
88

99
Version 2.0.8 (18 April 2019)
1010
-----------------------------
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
from .author import Author
2+
3+
4+
__all__ = ('Author',)

pylint_django/tests/input/models/func_noerror_foreign_key_key_cls_unbound.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
"""
55
# pylint: disable=missing-docstring,wrong-import-position
66
from django.db import models
7-
from django.db.models import ForeignKey
87

98

109
class FairyTail(models.Model):
11-
# this fails key_cls UnboundLocalError: local variable 'key_cls' referenced before assignment
10+
# fails with "UnboundLocalError: local variable 'key_cls' referenced before assignment"
1211
author = models.ForeignKey(to='input.Author', null=True, on_delete=models.CASCADE)
1312

1413
def get_author_name(self):

pylint_django/tests/input/models/func_noerror_foreign_key_package.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55
# pylint: disable=missing-docstring,wrong-import-position
66
from django.db import models
7-
from django.db.models import ForeignKey
87

98

109
class Book(models.Model):

pylint_django/transforms/foreignkey.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ def is_foreignkey_in_class(node):
2828
def _get_model_class_defs_from_module(module, model_name, module_name):
2929
class_defs = []
3030
for module_node in module.lookup(model_name)[1]:
31-
if isinstance(module_node, nodes.ClassDef) and node_is_subclass(
32-
module_node, "django.db.models.base.Model"
33-
):
31+
if (isinstance(module_node, nodes.ClassDef)
32+
and node_is_subclass(module_node, 'django.db.models.base.Model')):
3433
class_defs.append(module_node)
3534
elif isinstance(module_node, nodes.ImportFrom):
3635
imported_module = module_node.do_import_module()
@@ -90,11 +89,11 @@ def infer_key_classes(node, context=None):
9089
# 'auth.models', 'User' which works nicely with the `endswith()`
9190
# comparison below
9291
module_name += '.models'
93-
# ensure that module is loaded in cache, for cases when models is a package
92+
# ensure that module is loaded in astroid_cache, for cases when models is a package
9493
if module_name not in MANAGER.astroid_cache:
9594
MANAGER.ast_from_module_name(module_name)
9695

97-
# create list from dict_values, because it may be modified in loop
96+
# create list from dict_values, because it may be modified in a loop
9897
for module in list(MANAGER.astroid_cache.values()):
9998
# only load model classes from modules which match the module in
10099
# which *we think* they are defined. This will prevent infering

0 commit comments

Comments
 (0)