Hi Bruno,

On 4/17/24 3:18 PM, Bruno Haible wrote:
> In this example, the property 'attribute' is used outside of the class,
> that is, it is public. (In the OO world, the concept of "class" and of
> "private"/"public" are tightly related, because one of the main purposes
> of a class is to hide implementation details.)

True, but Python is different than the rest of the OO world because it
does not directly support "private"/"public". :(

There are ways to sort of emulate it but a single underscore is
simpler and gets the point across, as the "prior knowledge
summarization engine" suggests.

> Therefore, can you please see if after renaming message to _message the
> warning in GLError persists? If yes, please report a bug to the tool
> that produced this warning. The rationale why the warning is bogus is:
>   - The '_message' attribute is clearly private.
>   - Only one method uses it.
>   - There is no other convention for state that is used by one method only.

A single underscore doesn't silence it. I can submit a feature request
but it isn't really a bug since it is still an attribute outside of
__init__. IIRC pylint is pretty opinionated and they have many open
issues so who knows if it will even be addressed.

I'm not opposed to defining instance variables outside of __init__,
but I think that it should be more clear they are private. I'm happy
with the solution of a single underscore for private variables. The
functions I added in GLEmiter '_eliminate_NMD', etc. follow a similar
idea.

As far as silencing the warnings go, you can use a comment like so [1]:

   self.message = '[Errno %d] %s' % (errno, message)  # pylint: 
disable=attribute-defined-outside-init

but I can see that quickly becoming annoying if we make more use of
private variables. Since it would have to be placed in every block or
line one is defined.

How about we just silence this warning? I've attached a patch that
should work. I think the '_' prefix for private instance
variables/functions is a standard convention, but maybe we should add
a note in main.py?

Collin

[1] 
https://pylint.readthedocs.io/en/stable/user_guide/messages/message_control.html#block-disables
From b41ca5909ffe95d49f00a654d0fbb6dea2092340 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Wed, 17 Apr 2024 16:20:32 -0700
Subject: [PATCH] gnulib-tool.py: Ignore 'attribute-defined-outside-init'
 warnings.

* pygnulib/.pylintrc: Add W0201 to the disabled warnings.
See discussion here:
<https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00275.html>
---
 ChangeLog          | 7 +++++++
 pygnulib/.pylintrc | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 646653ffe5..d40063de73 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-04-17  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Ignore 'attribute-defined-outside-init' warnings.
+	* pygnulib/.pylintrc: Add W0201 to the disabled warnings.
+	See discussion here:
+	<https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00275.html>
+
 2024-04-17  Bruno Haible  <br...@clisp.org>
 
 	gnulib-tool.py: Use same warning style as gnulib-tool.sh.
diff --git a/pygnulib/.pylintrc b/pygnulib/.pylintrc
index 102accb37d..59fc986f13 100644
--- a/pygnulib/.pylintrc
+++ b/pygnulib/.pylintrc
@@ -1,7 +1,7 @@
 # .pylintrc
 
 [MESSAGES CONTROL]
-disable=C0103,C0114,C0121,C0123,C0209,C0301,C0302,R0902,R0912,R0913,R0914,R0915,R1705,R1702,R1720,R1735
+disable=C0103,C0114,C0121,C0123,C0209,C0301,C0302,R0902,R0912,R0913,R0914,R0915,R1705,R1702,R1720,R1735,W0201
 
 # Local Variables:
 # mode: conf
-- 
2.44.0

Reply via email to