summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakahide Nojima <nozzy123nozzy@gmail.com>2021-10-21 05:16:32 +0000
committerTakahide Nojima <nozzy123nozzy@gmail.com>2021-10-26 15:01:12 +0000
commit4e3acd8e4451ae39dbd5a6c8c5eba79300136d2f (patch)
treedf350f05c65092ff97c70e14f58788a5f61bf53b
parent9323cf20afff416dabe61b7f303791a1ce7f2bb6 (diff)
downloadpylint-git-4e3acd8e4451ae39dbd5a6c8c5eba79300136d2f.tar.gz
Fix exception of pyreverse in handling property function within a class.
-rw-r--r--CONTRIBUTORS.txt2
-rw-r--r--ChangeLog2
-rw-r--r--doc/whatsnew/2.12.rst2
-rw-r--r--pylint/pyreverse/diagrams.py1
-rw-r--r--tests/prop_data/property_pattern.py26
-rw-r--r--tests/pyreverse/test_diagrams.py27
6 files changed, 60 insertions, 0 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index 28b2e332c..8733bb995 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -564,3 +564,5 @@ contributors:
* Arianna Yang: contributor
* Mike Fiedler (miketheman): contributor
+
+* Takahide Nojima: contributor
diff --git a/ChangeLog b/ChangeLog
index 4e292305f..c9c0880ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,8 @@ Release date: TBA
..
Put new features here and also in 'doc/whatsnew/2.12.rst'
+* Fix exception when pyreverse parses ``property function`` of a class.
+
* Add an optional extension ``consider-using-any-or-all`` : Emitted when a ``for`` loop only
produces a boolean and could be replaced by ``any`` or ``all`` using a generator. Also suggests
a suitable any or all statement.
diff --git a/doc/whatsnew/2.12.rst b/doc/whatsnew/2.12.rst
index 6c71ae159..e4bb8ac47 100644
--- a/doc/whatsnew/2.12.rst
+++ b/doc/whatsnew/2.12.rst
@@ -64,6 +64,8 @@ Extensions
Other Changes
=============
+* Fix exception when pyreverse parses ``property function`` of a class.
+
* Improve and flatten ``unused-wildcard-import`` message
Closes #3859
diff --git a/pylint/pyreverse/diagrams.py b/pylint/pyreverse/diagrams.py
index 5c82df1e6..08a00a8f1 100644
--- a/pylint/pyreverse/diagrams.py
+++ b/pylint/pyreverse/diagrams.py
@@ -121,6 +121,7 @@ class ClassDiagram(Figure, FilterMixIn):
m
for m in node.values()
if isinstance(m, nodes.FunctionDef)
+ and not isinstance(m, astroid.objects.Property)
and not decorated_with_property(m)
and self.show_attr(m.name)
]
diff --git a/tests/prop_data/property_pattern.py b/tests/prop_data/property_pattern.py
new file mode 100644
index 000000000..77c7eee4b
--- /dev/null
+++ b/tests/prop_data/property_pattern.py
@@ -0,0 +1,26 @@
+""" docstring for file property_pattern.py """
+
+
+class FuncHolder:
+ def __init__(self, f_set, f_get, f_del, docstr):
+ pass
+
+
+class PropertyPatterns:
+ prop1 = property(lambda x: (x) * 2, None, None, "property usage 1")
+
+ @property
+ def prop2(self):
+ """property usage 2"""
+ return self._prop2
+
+ @prop2.setter
+ def prop2(self, value):
+ self._prop2 = value * 2
+
+ prop3 = FuncHolder(lambda x: (x) * 3, None, None, "non property 1")
+
+ prop4 = lambda self, x: x * 2 # noqa: E731
+
+ def __init__(self):
+ pass
diff --git a/tests/pyreverse/test_diagrams.py b/tests/pyreverse/test_diagrams.py
new file mode 100644
index 000000000..7e0cb4580
--- /dev/null
+++ b/tests/pyreverse/test_diagrams.py
@@ -0,0 +1,27 @@
+# Copyright (c) 2021 Takahide Nojima <nozzy123nozzy@gmail.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
+
+"""Unit test for the ClassDiagram modules"""
+# pylint: disable=redefined-outer-name
+from typing import Callable
+
+import pytest
+
+from pylint.pyreverse.diadefslib import DefaultDiadefGenerator, DiadefsHandler
+from pylint.pyreverse.inspector import Linker
+from pylint.testutils.pyreverse import PyreverseConfig
+
+
+@pytest.fixture
+def HANDLER(default_config: PyreverseConfig) -> DiadefsHandler:
+ return DiadefsHandler(default_config)
+
+
+def test_property_handling(HANDLER: DiadefsHandler, get_project: Callable) -> None:
+ project = get_project("prop_data.property_pattern")
+ cd = DefaultDiadefGenerator(Linker(project), HANDLER).visit(project)[0]
+ obj = cd.classe("PropertyPatterns")
+ assert len(cd.get_methods(obj.node)) == 0
+ assert cd.get_attrs(obj.node) == ["prop1", "prop2", "prop3", "prop4"]