Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
imomaliev committed Apr 23, 2019
1 parent c797a51 commit 859d658
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Changelog
=========

Version 2.0.8 (18 April 2019)
Version 2.0.9 (dev)
-----------------------------

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

Version 2.0.8 (18 April 2019)
-----------------------------
Expand Down
3 changes: 3 additions & 0 deletions pylint_django/tests/input/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from .author import Author


__all__ = ('Author',)
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"""
# pylint: disable=missing-docstring,wrong-import-position
from django.db import models
from django.db.models import ForeignKey


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

def get_author_name(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""
# pylint: disable=missing-docstring,wrong-import-position
from django.db import models
from django.db.models import ForeignKey


class Book(models.Model):
Expand Down
9 changes: 4 additions & 5 deletions pylint_django/transforms/foreignkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ def is_foreignkey_in_class(node):
def _get_model_class_defs_from_module(module, model_name, module_name):
class_defs = []
for module_node in module.lookup(model_name)[1]:
if isinstance(module_node, nodes.ClassDef) and node_is_subclass(
module_node, "django.db.models.base.Model"
):
if (isinstance(module_node, nodes.ClassDef)
and node_is_subclass(module_node, 'django.db.models.base.Model')):
class_defs.append(module_node)
elif isinstance(module_node, nodes.ImportFrom):
imported_module = module_node.do_import_module()
Expand Down Expand Up @@ -90,11 +89,11 @@ def infer_key_classes(node, context=None):
# 'auth.models', 'User' which works nicely with the `endswith()`
# comparison below
module_name += '.models'
# ensure that module is loaded in cache, for cases when models is a package
# ensure that module is loaded in astroid_cache, for cases when models is a package
if module_name not in MANAGER.astroid_cache:
MANAGER.ast_from_module_name(module_name)

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

0 comments on commit 859d658

Please sign in to comment.