forked from pylint-dev/pylint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ignored-parents option to design checker
This allows users to specify classes to ignore while counting parent classes. Partially closes pylint-dev#3057
- Loading branch information
Rebecca Turner
committed
Jul 27, 2021
1 parent
e04de25
commit 1c2b07e
Showing
5 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright (c) 2021 Rebecca Turner <rturner@starry.com> | ||
|
||
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html | ||
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE | ||
|
||
import os | ||
import re | ||
import sys | ||
import unittest | ||
from pathlib import Path | ||
|
||
import astroid | ||
|
||
from pylint.checkers import design_analysis | ||
from pylint.testutils import CheckerTestCase, Message, linter, set_config | ||
|
||
REGR_DATA_DIR = str(Path(__file__).parent / ".." / "regrtest_data") | ||
|
||
|
||
class TestDesignChecker(CheckerTestCase): | ||
|
||
CHECKER_CLASS = design_analysis.MisdesignChecker | ||
|
||
@set_config( | ||
ignored_parents=(".Dddd",), | ||
max_parents=1, | ||
) | ||
def test_too_many_ancestors_ignored_parents_are_skipped(self): | ||
"""Make sure that classes listed in ``ignored-parents`` aren't counted | ||
by the too-many-ancestors message. | ||
""" | ||
|
||
node = astroid.extract_node( | ||
""" | ||
class Aaaa(object): | ||
pass | ||
class Bbbb(Aaaa): | ||
pass | ||
class Cccc(Bbbb): | ||
pass | ||
class Dddd(Cccc): | ||
pass | ||
class Eeee(Dddd): | ||
pass | ||
""" | ||
) | ||
with self.assertNoMessages(): | ||
self.checker.visit_classdef(node) | ||
|