public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Donald Hunter <donald.hunter@gmail.com>
Cc: Linux Doc Mailing List <linux-doc@vger.kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	"Akira Yokosawa" <akiyks@gmail.com>,
	"Breno Leitao" <leitao@debian.org>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Ignacio Encinas Rubio" <ignacio@iencinas.com>,
	"Jan Stancek" <jstancek@redhat.com>,
	"Marco Elver" <elver@google.com>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Ruben Wauters" <rubenru09@aol.com>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	joel@joelfernandes.org, linux-kernel-mentees@lists.linux.dev,
	linux-kernel@vger.kernel.org, lkmm@lists.linux.dev,
	netdev@vger.kernel.org, peterz@infradead.org,
	stern@rowland.harvard.edu
Subject: Re: [PATCH v8 11/13] tools: netlink_yml_parser.py: add line numbers to parsed data
Date: Wed, 9 Jul 2025 17:44:40 +0200	[thread overview]
Message-ID: <20250709174440.39b0f49e@sal.lan> (raw)
In-Reply-To: <m2bjq98n10.fsf@gmail.com>

Em Fri, 27 Jun 2025 12:03:07 +0100
Donald Hunter <donald.hunter@gmail.com> escreveu:

> 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)

I'm yet to find any pylint Rxxx warning that I didn't have to
disable ;-)

This particular one is useless for us, as it basically tells that PyYAML
has a big class hierarchy.

> 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)

I'll fix this one to prevent potential future issues.

Changing the code to:
 
-class NumberedSafeLoader(yaml.SafeLoader):
+class NumberedSafeLoader(yaml.SafeLoader):              # pylint: disable=R0901
     """Override the SafeLoader class to add line number to parsed data"""
 
-    def construct_mapping(self, node):
-        mapping = super().construct_mapping(node)
+    def construct_mapping(self, node, *args, **kwargs):
+        mapping = super().construct_mapping(node, *args, **kwargs)
         mapping[LINE_STR] = node.start_mark.line
 
         return mapping

This should hopefully be future-proof.

Regards,
Mauro



  reply	other threads:[~2025-07-09 15:44 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-26  8:12 [PATCH v8 00/13] Don't generate netlink .rst files inside $(srctree) Mauro Carvalho Chehab
2025-06-26  8:12 ` [PATCH v8 01/13] docs: netlink: netlink-raw.rst: use :ref: instead of :doc: Mauro Carvalho Chehab
2025-06-26  8:12 ` [PATCH v8 02/13] tools: ynl_gen_rst.py: Split library from command line tool Mauro Carvalho Chehab
2025-06-27 10:29   ` Donald Hunter
2025-06-26  8:12 ` [PATCH v8 03/13] docs: netlink: index.rst: add a netlink index file Mauro Carvalho Chehab
2025-06-26  8:13 ` [PATCH v8 04/13] tools: ynl_gen_rst.py: cleanup coding style Mauro Carvalho Chehab
2025-06-27 10:41   ` Donald Hunter
2025-06-26  8:13 ` [PATCH v8 05/13] docs: sphinx: add a parser for yaml files for Netlink specs Mauro Carvalho Chehab
2025-06-27 10:25   ` Donald Hunter
2025-06-26  8:13 ` [PATCH v8 06/13] docs: use parser_yaml extension to handle " Mauro Carvalho Chehab
2025-06-27 10:28   ` Donald Hunter
2025-07-09 15:25     ` Mauro Carvalho Chehab
2025-06-26  8:13 ` [PATCH v8 07/13] docs: uapi: netlink: update netlink specs link Mauro Carvalho Chehab
2025-06-26  8:13 ` [PATCH v8 08/13] tools: ynl_gen_rst.py: drop support for generating index files Mauro Carvalho Chehab
2025-06-27 10:49   ` Donald Hunter
2025-06-26  8:13 ` [PATCH v8 09/13] docs: netlink: remove obsolete .gitignore from unused directory Mauro Carvalho Chehab
2025-06-26  8:13 ` [PATCH v8 10/13] MAINTAINERS: add netlink_yml_parser.py to linux-doc Mauro Carvalho Chehab
2025-06-27 10:50   ` Donald Hunter
2025-06-26  8:13 ` [PATCH v8 11/13] tools: netlink_yml_parser.py: add line numbers to parsed data Mauro Carvalho Chehab
2025-06-27 11:03   ` Donald Hunter
2025-07-09 15:44     ` Mauro Carvalho Chehab [this message]
2025-06-26  8:13 ` [PATCH v8 12/13] docs: parser_yaml.py: add support for line numbers from the parser Mauro Carvalho Chehab
2025-06-26  8:13 ` [PATCH v8 13/13] docs: parser_yaml.py: fix backward compatibility with old docutils Mauro Carvalho Chehab
2025-06-26 23:59   ` Akira Yokosawa
2025-06-27  6:48     ` Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250709174440.39b0f49e@sal.lan \
    --to=mchehab+huawei@kernel.org \
    --cc=akiyks@gmail.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@google.com \
    --cc=elver@google.com \
    --cc=ignacio@iencinas.com \
    --cc=joel@joelfernandes.org \
    --cc=jstancek@redhat.com \
    --cc=leitao@debian.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkmm@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=rubenru09@aol.com \
    --cc=skhan@linuxfoundation.org \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox