diff options
author | Téo Bouvard <teobouvard@gmail.com> | 2022-03-09 17:43:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-09 17:43:40 +0100 |
commit | 1ebdc8c59f31962db0244a79eaab9b8d90a87baf (patch) | |
tree | 30e3ec2963f3109a8371b38217f4318aca04835e /tests/pyreverse/test_printer.py | |
parent | b1bb7f86bf08876e909fe135802a262fb2e5d82f (diff) | |
download | pylint-git-1ebdc8c59f31962db0244a79eaab9b8d90a87baf.tar.gz |
Fix pyreverse type hinting for class methods (#5881)
* Fix pyreverse type hinting for class methods
This commit fixes the alignment of arguments and their type annotations
in pyreverse printer output. It does so by checking for the type of the
current function rather than the name of the first argument.
This allows class methods having a non-standard first argument
(different from "self" or "cls") to be correctly serialized in class
diagrams.
* Add test for method with None args
According to astroid docs, this happens for builtin functions
implemented in C. In this case, we return an empty argument list.
Diffstat (limited to 'tests/pyreverse/test_printer.py')
-rw-r--r-- | tests/pyreverse/test_printer.py | 10 |
1 files changed, 10 insertions, 0 deletions
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) |