summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--pylint/pyreverse/printer.py15
-rw-r--r--tests/data/clientmodule_test.py8
-rw-r--r--tests/pyreverse/data/classes_No_Name.dot2
-rw-r--r--tests/pyreverse/data/classes_No_Name.html2
-rw-r--r--tests/pyreverse/data/classes_No_Name.mmd2
-rw-r--r--tests/pyreverse/data/classes_No_Name.puml2
-rw-r--r--tests/pyreverse/data/classes_No_Name.vcg2
-rw-r--r--tests/pyreverse/data/classes_colorized.dot2
-rw-r--r--tests/pyreverse/data/classes_colorized.puml2
-rw-r--r--tests/pyreverse/test_printer.py10
11 files changed, 38 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index b4c72ba03..d97f87c9f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,8 @@ Release date: TBA
..
Put new features here and also in 'doc/whatsnew/2.13.rst'
+* Fix pyreverse diagrams type hinting for classmethods and staticmethods.
+
* Fix matching ``--notes`` options that end in a non-word character.
Closes #5840
diff --git a/pylint/pyreverse/printer.py b/pylint/pyreverse/printer.py
index 559e456be..ca7f9b0a2 100644
--- a/pylint/pyreverse/printer.py
+++ b/pylint/pyreverse/printer.py
@@ -99,14 +99,13 @@ class Printer(ABC):
@staticmethod
def _get_method_arguments(method: nodes.FunctionDef) -> List[str]:
- if method.args.args:
- arguments: List[nodes.AssignName] = [
- arg for arg in method.args.args if arg.name != "self"
- ]
- else:
- arguments = []
-
- annotations = dict(zip(arguments, method.args.annotations[1:]))
+ if method.args.args is None:
+ return []
+
+ first_arg = 0 if method.type in {"function", "staticmethod"} else 1
+ arguments: List[nodes.AssignName] = method.args.args[first_arg:]
+
+ annotations = dict(zip(arguments, method.args.annotations[first_arg:]))
for arg in arguments:
annotation_label = ""
ann = annotations.get(arg)
diff --git a/tests/data/clientmodule_test.py b/tests/data/clientmodule_test.py
index 82deaaf6f..257aadec1 100644
--- a/tests/data/clientmodule_test.py
+++ b/tests/data/clientmodule_test.py
@@ -28,3 +28,11 @@ class Specialization(Ancestor):
self._id = _id
self.relation = DoNothing()
self.relation2 = relation2
+
+ @classmethod
+ def from_value(cls, value: int):
+ return cls(value, 0, DoNothing2())
+
+ @staticmethod
+ def transform_value(value: int) -> int:
+ return value * 2
diff --git a/tests/pyreverse/data/classes_No_Name.dot b/tests/pyreverse/data/classes_No_Name.dot
index b2c555108..e5a304ce3 100644
--- a/tests/pyreverse/data/classes_No_Name.dot
+++ b/tests/pyreverse/data/classes_No_Name.dot
@@ -8,7 +8,7 @@ charset="utf-8"
"data.suppliermodule_test.DoSomething" [color="black", fontcolor="black", label="{DoSomething|my_int : Optional[int]\lmy_int_2 : Optional[int]\lmy_string : str\l|do_it(new_int: int): int\l}", shape="record", style="solid"];
"data.suppliermodule_test.Interface" [color="black", fontcolor="black", label="{Interface|\l|get_value()\lset_value(value)\l}", shape="record", style="solid"];
"data.property_pattern.PropertyPatterns" [color="black", fontcolor="black", label="{PropertyPatterns|prop1\lprop2\l|}", shape="record", style="solid"];
-"data.clientmodule_test.Specialization" [color="black", fontcolor="black", label="{Specialization|TYPE : str\lrelation\lrelation2\ltop : str\l|}", shape="record", style="solid"];
+"data.clientmodule_test.Specialization" [color="black", fontcolor="black", label="{Specialization|TYPE : str\lrelation\lrelation2\ltop : str\l|from_value(value: int)\ltransform_value(value: int): int\l}", shape="record", style="solid"];
"data.clientmodule_test.Specialization" -> "data.clientmodule_test.Ancestor" [arrowhead="empty", arrowtail="none"];
"data.clientmodule_test.Ancestor" -> "data.suppliermodule_test.Interface" [arrowhead="empty", arrowtail="node", style="dashed"];
"data.suppliermodule_test.DoNothing" -> "data.clientmodule_test.Ancestor" [arrowhead="diamond", arrowtail="none", fontcolor="green", label="cls_member", style="solid"];
diff --git a/tests/pyreverse/data/classes_No_Name.html b/tests/pyreverse/data/classes_No_Name.html
index 3f81c340e..420a869d4 100644
--- a/tests/pyreverse/data/classes_No_Name.html
+++ b/tests/pyreverse/data/classes_No_Name.html
@@ -35,6 +35,8 @@
relation
relation2
top : str
+ from_value(value: int)
+ transform_value(value: int) -> int
}
Specialization --|> Ancestor
Ancestor ..|> Interface
diff --git a/tests/pyreverse/data/classes_No_Name.mmd b/tests/pyreverse/data/classes_No_Name.mmd
index d2ac9839d..50da7f39c 100644
--- a/tests/pyreverse/data/classes_No_Name.mmd
+++ b/tests/pyreverse/data/classes_No_Name.mmd
@@ -30,6 +30,8 @@ classDiagram
relation
relation2
top : str
+ from_value(value: int)
+ transform_value(value: int) -> int
}
Specialization --|> Ancestor
Ancestor ..|> Interface
diff --git a/tests/pyreverse/data/classes_No_Name.puml b/tests/pyreverse/data/classes_No_Name.puml
index 1d9e5f37d..a0f8350d0 100644
--- a/tests/pyreverse/data/classes_No_Name.puml
+++ b/tests/pyreverse/data/classes_No_Name.puml
@@ -31,6 +31,8 @@ class "Specialization" as data.clientmodule_test.Specialization {
relation
relation2
top : str
+ from_value(value: int)
+ transform_value(value: int) -> int
}
data.clientmodule_test.Specialization --|> data.clientmodule_test.Ancestor
data.clientmodule_test.Ancestor ..|> data.suppliermodule_test.Interface
diff --git a/tests/pyreverse/data/classes_No_Name.vcg b/tests/pyreverse/data/classes_No_Name.vcg
index bc542b64b..6497f26b4 100644
--- a/tests/pyreverse/data/classes_No_Name.vcg
+++ b/tests/pyreverse/data/classes_No_Name.vcg
@@ -25,7 +25,7 @@ graph:{
node: {title:"data.property_pattern.PropertyPatterns" label:"\fbPropertyPatterns\fn\n\f__________________\n\f08prop1\n\f08prop2\n\f__________________"
shape:box
}
- node: {title:"data.clientmodule_test.Specialization" label:"\fbSpecialization\fn\n\f________________\n\f08TYPE : str\n\f08relation\n\f08relation2\n\f08top : str\n\f________________"
+ node: {title:"data.clientmodule_test.Specialization" label:"\fbSpecialization\fn\n\f_________________\n\f08TYPE : str\n\f08relation\n\f08relation2\n\f08top : str\n\f_________________\n\f10from_value()\n\f10transform_value()"
shape:box
}
edge: {sourcename:"data.clientmodule_test.Specialization" targetname:"data.clientmodule_test.Ancestor" arrowstyle:solid
diff --git a/tests/pyreverse/data/classes_colorized.dot b/tests/pyreverse/data/classes_colorized.dot
index 0ed328566..3b68c7933 100644
--- a/tests/pyreverse/data/classes_colorized.dot
+++ b/tests/pyreverse/data/classes_colorized.dot
@@ -8,7 +8,7 @@ charset="utf-8"
"data.suppliermodule_test.DoSomething" [color="aliceblue", fontcolor="black", label="{DoSomething|my_int : Optional[int]\lmy_int_2 : Optional[int]\lmy_string : str\l|do_it(new_int: int): int\l}", shape="record", style="filled"];
"data.suppliermodule_test.Interface" [color="aliceblue", fontcolor="black", label="{Interface|\l|get_value()\lset_value(value)\l}", shape="record", style="filled"];
"data.property_pattern.PropertyPatterns" [color="aliceblue", fontcolor="black", label="{PropertyPatterns|prop1\lprop2\l|}", shape="record", style="filled"];
-"data.clientmodule_test.Specialization" [color="aliceblue", fontcolor="black", label="{Specialization|TYPE : str\lrelation\lrelation2\ltop : str\l|}", shape="record", style="filled"];
+"data.clientmodule_test.Specialization" [color="aliceblue", fontcolor="black", label="{Specialization|TYPE : str\lrelation\lrelation2\ltop : str\l|from_value(value: int)\ltransform_value(value: int): int\l}", shape="record", style="filled"];
"data.clientmodule_test.Specialization" -> "data.clientmodule_test.Ancestor" [arrowhead="empty", arrowtail="none"];
"data.clientmodule_test.Ancestor" -> "data.suppliermodule_test.Interface" [arrowhead="empty", arrowtail="node", style="dashed"];
"data.suppliermodule_test.DoNothing" -> "data.clientmodule_test.Ancestor" [arrowhead="diamond", arrowtail="none", fontcolor="green", label="cls_member", style="solid"];
diff --git a/tests/pyreverse/data/classes_colorized.puml b/tests/pyreverse/data/classes_colorized.puml
index 611a669db..8a37f090f 100644
--- a/tests/pyreverse/data/classes_colorized.puml
+++ b/tests/pyreverse/data/classes_colorized.puml
@@ -31,6 +31,8 @@ class "Specialization" as data.clientmodule_test.Specialization #aliceblue {
relation
relation2
top : str
+ from_value(value: int)
+ transform_value(value: int) -> int
}
data.clientmodule_test.Specialization --|> data.clientmodule_test.Ancestor
data.clientmodule_test.Ancestor ..|> data.suppliermodule_test.Interface
diff --git a/tests/pyreverse/test_printer.py b/tests/pyreverse/test_printer.py
index 6d240c836..5406c6e83 100644
--- a/tests/pyreverse/test_printer.py
+++ b/tests/pyreverse/test_printer.py
@@ -8,6 +8,7 @@
from typing import Type
import pytest
+from astroid import nodes
from pylint.pyreverse.dot_printer import DotPrinter
from pylint.pyreverse.plantuml_printer import PlantUmlPrinter
@@ -46,6 +47,15 @@ def test_unsupported_layout(layout: Layout, printer_class: Type[Printer]):
printer_class(title="unittest", layout=layout)
+def test_method_arguments_none():
+ func = nodes.FunctionDef()
+ args = nodes.Arguments()
+ args.args = None
+ func.postinit(args, body=None)
+ parsed_args = Printer._get_method_arguments(func)
+ assert parsed_args == []
+
+
class TestPlantUmlPrinter:
printer = PlantUmlPrinter(title="unittest", layout=Layout.TOP_TO_BOTTOM)