Skip to content

Support factory_boy's DjangoModelFactory Meta class #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pylint_django/augmentations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,16 @@ def is_model_meta_subclass(node):
return node_is_subclass(node.parent, *parents)


def is_model_factory_meta_subclass(node):
"""Checks that node is derivative of DjangoModelFactory class."""
if node.name != 'Meta' or not isinstance(node.parent, ClassDef):
return False

parents = ('factory.django.DjangoModelFactory',
'.DjangoModelFactory',)
return node_is_subclass(node.parent, *parents)


def is_model_mpttmeta_subclass(node):
"""Checks that node is derivative of MPTTMeta class."""
if node.name != 'MPTTMeta' or not isinstance(node.parent, ClassDef):
Expand Down Expand Up @@ -772,6 +782,12 @@ def apply_augmentations(linter):
suppress_message(linter, _visit_class(ClassChecker), 'W0232', is_model_mpttmeta_subclass)
suppress_message(linter, _leave_class(MisdesignChecker), 'too-few-public-methods', is_model_mpttmeta_subclass)

# factory_boy's DjangoModelFactory
suppress_message(linter, _visit_class(DocStringChecker), 'missing-docstring', is_model_factory_meta_subclass)
suppress_message(linter, _visit_class(NewStyleConflictChecker), 'old-style-class', is_model_factory_meta_subclass)
suppress_message(linter, _visit_class(ClassChecker), 'W0232', is_model_factory_meta_subclass)
suppress_message(linter, _leave_class(MisdesignChecker), 'too-few-public-methods', is_model_factory_meta_subclass)

# ForeignKey and OneToOneField
# Must update this in a thread safe way to support the parallel option on pylint (-j)
current_leave_module = VariablesChecker.leave_module
Expand Down