Re: [PATCH v8 11/13] tools: netlink_yml_parser.py: add line numbers to parsed data

Donald Hunter
2025-06-27T11:05:06Z

Mauro Carvalho Chehab <mchehab+huawei@kernel.org> writes:

> When something goes wrong, we want Sphinx error to point to the
> right line number from the original source, not from the
> processed ReST data.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
> tools/net/ynl/pyynl/lib/doc_generator.py | 34 ++++++++++++++++++++++--
> 1 file changed, 32 insertions(+), 2 deletions(-)
>
> diff --git a/tools/net/ynl/pyynl/lib/doc_generator.py b/tools/net/ynl/pyynl/lib/doc_generator.py
> index 866551726723..a9d8ab6f2639 100644
> --- a/tools/net/ynl/pyynl/lib/doc_generator.py
> +++ b/tools/net/ynl/pyynl/lib/doc_generator.py
> @@ -20,6 +20,16 @@
> from typing import Any, Dict, List
> import yaml
>
> +LINE_STR = '__lineno__'
> +
> +class NumberedSafeLoader(yaml.SafeLoader):
> + """Override the SafeLoader class to add line number to parsed data"""
> +
> + def construct_mapping(self, node):
> + mapping = super().construct_mapping(node)
> + mapping[LINE_STR] = node.start_mark.line
> +
> + return mapping

pylint gives these 2 warnings:

tools/net/ynl/pyynl/lib/doc_generator.py:25:0: R0901: Too many ancestors (9/7) (too-many-ancestors)
tools/net/ynl/pyynl/lib/doc_generator.py:28:4: W0221: Number of parameters was 3 in 'SafeConstructor.construct_mapping' and is now 2 in overriding 'NumberedSafeLoader.construct_mapping' method (arguments-differ)