summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Finkler <3929834+DudeNr33@users.noreply.github.com>2023-01-08 12:16:10 +0100
committerGitHub <noreply@github.com>2023-01-08 12:16:10 +0100
commit91513a09513c7cc54e78f38999aa5fda4c77625d (patch)
treed277d2e4c8a93adf0d2f9815c7c676aeea8626bc
parent89a20e2ccdb2927ac370f7c6663fc83318988e10 (diff)
downloadpylint-git-91513a09513c7cc54e78f38999aa5fda4c77625d.tar.gz
Prevent `pyreverse` crash when processing attributes assigned via tuple unpacking (#8032)
-rw-r--r--pylint/pyreverse/inspector.py4
-rw-r--r--tests/pyreverse/functional/class_diagrams/regression/regression_8031.mmd5
-rw-r--r--tests/pyreverse/functional/class_diagrams/regression/regression_8031.py4
3 files changed, 12 insertions, 1 deletions
diff --git a/pylint/pyreverse/inspector.py b/pylint/pyreverse/inspector.py
index 8c403ffc6..af97cdb33 100644
--- a/pylint/pyreverse/inspector.py
+++ b/pylint/pyreverse/inspector.py
@@ -365,7 +365,9 @@ class AbstractAssociationHandler(AssociationHandlerInterface):
class AggregationsHandler(AbstractAssociationHandler):
def handle(self, node: nodes.AssignAttr, parent: nodes.ClassDef) -> None:
- if isinstance(node.parent.value, astroid.node_classes.Name):
+ if isinstance(node.parent, (nodes.AnnAssign, nodes.Assign)) and isinstance(
+ node.parent.value, astroid.node_classes.Name
+ ):
current = set(parent.aggregations_type[node.attrname])
parent.aggregations_type[node.attrname] = list(
current | utils.infer_node(node)
diff --git a/tests/pyreverse/functional/class_diagrams/regression/regression_8031.mmd b/tests/pyreverse/functional/class_diagrams/regression/regression_8031.mmd
new file mode 100644
index 000000000..7ca9a6462
--- /dev/null
+++ b/tests/pyreverse/functional/class_diagrams/regression/regression_8031.mmd
@@ -0,0 +1,5 @@
+classDiagram
+ class MyClass {
+ a
+ b
+ }
diff --git a/tests/pyreverse/functional/class_diagrams/regression/regression_8031.py b/tests/pyreverse/functional/class_diagrams/regression/regression_8031.py
new file mode 100644
index 000000000..db56c37af
--- /dev/null
+++ b/tests/pyreverse/functional/class_diagrams/regression/regression_8031.py
@@ -0,0 +1,4 @@
+class MyClass:
+
+ def __init__(self, a, b):
+ self.a, self.b = a, b