diff options
author | Avram Lubkin <avylove@rockhopper.net> | 2023-03-10 13:23:03 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-10 19:23:03 +0100 |
commit | 958ff856a25c1b6152c6f0a03d7488a6278adebf (patch) | |
tree | 15bc188a818f68b1f7239fac922aa52099d96eeb /pylint/pyreverse | |
parent | ed8b840c5439ead350ba815c7fc02157d58166b1 (diff) | |
download | pylint-git-958ff856a25c1b6152c6f0a03d7488a6278adebf.tar.gz |
pyreverse: Add show-stdlib option (#8190)
* pyreverse: Add show-stdlib option
* Switch to astroid.modutils.is_standard_module
* Add tests
* Fix quotes in whatsnew fragment
* Update for astroid 2.15.0
* Recategorize news fragment
Diffstat (limited to 'pylint/pyreverse')
-rw-r--r-- | pylint/pyreverse/diadefslib.py | 13 | ||||
-rw-r--r-- | pylint/pyreverse/main.py | 9 |
2 files changed, 18 insertions, 4 deletions
diff --git a/pylint/pyreverse/diadefslib.py b/pylint/pyreverse/diadefslib.py index 85b23052e..5f12eaf7c 100644 --- a/pylint/pyreverse/diadefslib.py +++ b/pylint/pyreverse/diadefslib.py @@ -12,6 +12,7 @@ from typing import Any import astroid from astroid import nodes +from astroid.modutils import is_stdlib_module from pylint.pyreverse.diagrams import ClassDiagram, PackageDiagram from pylint.pyreverse.inspector import Linker, Project @@ -67,10 +68,14 @@ class DiaDefGenerator: return self.anc_level, self.association_level def show_node(self, node: nodes.ClassDef) -> bool: - """True if builtins and not show_builtins.""" - if self.config.show_builtin: - return True - return node.root().name != "builtins" # type: ignore[no-any-return] + """Determine if node should be shown based on config.""" + if node.root().name == "builtins": + return self.config.show_builtin # type: ignore[no-any-return] + + if is_stdlib_module(node.root().name): + return self.config.show_stdlib # type: ignore[no-any-return] + + return True def add_class(self, node: nodes.ClassDef) -> None: """Visit one class and add it to diagram.""" diff --git a/pylint/pyreverse/main.py b/pylint/pyreverse/main.py index a2dc94734..bdd1eb4a9 100644 --- a/pylint/pyreverse/main.py +++ b/pylint/pyreverse/main.py @@ -138,6 +138,15 @@ OPTIONS: Options = ( }, ), ( + "show-stdlib", + { + "short": "L", + "action": "store_true", + "default": False, + "help": "include standard library objects in representation of classes", + }, + ), + ( "module-names", { "short": "m", |