bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Collin Funk <collin.funk1@gmail.com>
To: bug-gnulib@gnu.org
Subject: gnulib-tool.py: Ignore pylint 'unidiomatic-typecheck' warnings.
Date: Wed, 3 Apr 2024 03:22:36 -0700	[thread overview]
Message-ID: <e4cced80-b67b-45ae-82bf-b62a84873cd5@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1150 bytes --]

I'm trying to fix some easy things to make warnings more meaningful.
Here is two patches for that.

The first adds an option to the pylintrc configuration file. Right now
the pylint output gets spammed with 'unidiomatic-typecheck' warnings.
This is because we use:

     if type(var) is str:

instead of:

    if isinstance(var, str):

I think we discussed this previously and concluded it wasn't
important. The warning spam is more likely to cause problems than the
difference between these two conditions, in my opinion.

The second just removes the explicit inheritance from 'object' from
our class declarations. Pylint warns about this, but it also feels
like more "standard" Python 3 to me. The implicit object inheritance
was added over 20 years ago, so I don't see any issues with it [1].

Not that this is likely to cause any issues, but since it is Python
you can do interesting things like this:

    #!/usr/bin/env python3
    object = str
    class MyClass(object):
        def __init__(self) -> None:
            pass
    # Prints "(<class 'str'>,)".
    print(MyClass.__bases__)

[1] https://docs.python.org/3/whatsnew/2.2.html

Collin

[-- Attachment #2: 0001-gnulib-tool.py-Ignore-pylint-unidiomatic-typecheck-w.patch --]
[-- Type: text/x-patch, Size: 1350 bytes --]

From c7c58f26e1469d4dd77da5e91b8591add12005c5 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.funk1@gmail.com>
Date: Wed, 3 Apr 2024 02:25:53 -0700
Subject: [PATCH 1/2] gnulib-tool.py: Ignore pylint 'unidiomatic-typecheck'
 warnings.

* pygnulib/.pylintrc: Disable warning C0123 since we don't mind using
'type() is' instead of 'isinstance'.
---
 ChangeLog          | 6 ++++++
 pygnulib/.pylintrc | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 068fe06662..333f7cd0cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-04-03  Collin Funk  <collin.funk1@gmail.com>
+
+	gnulib-tool.py: Ignore pylint 'unidiomatic-typecheck' warnings.
+	* pygnulib/.pylintrc: Disable warning C0123 since we don't mind using
+	'type() is' instead of 'isinstance'.
+
 2024-04-02  Collin Funk  <collin.funk1@gmail.com>
 
 	gnulib-tool.py: Don't ignore the argument to --doc-base.
diff --git a/pygnulib/.pylintrc b/pygnulib/.pylintrc
index 7c4c1a338c..15e2e8e800 100644
--- a/pygnulib/.pylintrc
+++ b/pygnulib/.pylintrc
@@ -1,7 +1,7 @@
 # .pylintrc
 
 [MESSAGES CONTROL]
-disable=C0103,C0114,C0121,C0209,C0301,C0302,R0902,R0912,R0913,R0914,R0915,R1705,R1702,R1720
+disable=C0103,C0114,C0121,C0123,C0209,C0301,C0302,R0902,R0912,R0913,R0914,R0915,R1705,R1702,R1720
 
 # Local Variables:
 # mode: conf
-- 
2.44.0


[-- Attachment #3: 0002-gnulib-tool.py-Modernize-class-declarations-to-Pytho.patch --]
[-- Type: text/x-patch, Size: 8630 bytes --]

From 447378fd3d0384e7e138ef726721cf657ec75873 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.funk1@gmail.com>
Date: Wed, 3 Apr 2024 02:56:42 -0700
Subject: [PATCH 2/2] gnulib-tool.py: Modernize class declarations to Python 3.

* pygnulib/GLConfig.py: Remove the explicit object inheritance from
class declarations. This is previously required in Python 2.
* pygnulib/GLEmiter.py: Likewise.
* pygnulib/GLFileSystem.py: Likewise.
* pygnulib/GLImport.py: Likewise.
* pygnulib/GLInfo.py: Likewise.
* pygnulib/GLMakefileTable.py: Likewise.
* pygnulib/GLModuleSystem.py: Likewise.
* pygnulib/GLTestDir.py: Likewise.
---
 ChangeLog                   | 13 +++++++++++++
 pygnulib/GLConfig.py        |  2 +-
 pygnulib/GLEmiter.py        |  2 +-
 pygnulib/GLFileSystem.py    |  4 ++--
 pygnulib/GLImport.py        |  2 +-
 pygnulib/GLInfo.py          |  2 +-
 pygnulib/GLMakefileTable.py |  2 +-
 pygnulib/GLModuleSystem.py  |  6 +++---
 pygnulib/GLTestDir.py       |  4 ++--
 9 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 333f7cd0cb..230e9c5925 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-04-03  Collin Funk  <collin.funk1@gmail.com>
+
+	gnulib-tool.py: Modernize class declarations to Python 3.
+	* pygnulib/GLConfig.py: Remove the explicit object inheritance from
+	class declarations. This is previously required in Python 2.
+	* pygnulib/GLEmiter.py: Likewise.
+	* pygnulib/GLFileSystem.py: Likewise.
+	* pygnulib/GLImport.py: Likewise.
+	* pygnulib/GLInfo.py: Likewise.
+	* pygnulib/GLMakefileTable.py: Likewise.
+	* pygnulib/GLModuleSystem.py: Likewise.
+	* pygnulib/GLTestDir.py: Likewise.
+
 2024-04-03  Collin Funk  <collin.funk1@gmail.com>
 
 	gnulib-tool.py: Ignore pylint 'unidiomatic-typecheck' warnings.
diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py
index 10ec5efd37..8136d9b08c 100644
--- a/pygnulib/GLConfig.py
+++ b/pygnulib/GLConfig.py
@@ -49,7 +49,7 @@ normpath = os.path.normpath
 #===============================================================================
 # Define GLConfig class
 #===============================================================================
-class GLConfig(object):
+class GLConfig:
     '''This class is used to store intermediate settings for all pygnulib
     classes. It contains all necessary attributes to setup any other class.
     By default all attributes are set to empty string, empty list or zero.
diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py
index 186d94bb92..cb813b3baa 100644
--- a/pygnulib/GLEmiter.py
+++ b/pygnulib/GLEmiter.py
@@ -107,7 +107,7 @@ def _eliminate_NMD(snippet: str, automake_subdir: bool) -> str:
 #===============================================================================
 # Define GLEmiter class
 #===============================================================================
-class GLEmiter(object):
+class GLEmiter:
     '''This class is used to emit the contents of necessary files.'''
 
     def __init__(self, config: GLConfig) -> None:
diff --git a/pygnulib/GLFileSystem.py b/pygnulib/GLFileSystem.py
index cb485cf2e8..a0cddd8903 100644
--- a/pygnulib/GLFileSystem.py
+++ b/pygnulib/GLFileSystem.py
@@ -55,7 +55,7 @@ islink = os.path.islink
 #===============================================================================
 # Define GLFileSystem class
 #===============================================================================
-class GLFileSystem(object):
+class GLFileSystem:
     '''GLFileSystem class is used to create virtual filesystem, which is based
     on the gnulib directory and directories specified by localpath argument.
     Its main method lookup(file) is used to find file in these directories or
@@ -151,7 +151,7 @@ class GLFileSystem(object):
 #===============================================================================
 # Define GLFileAssistant class
 #===============================================================================
-class GLFileAssistant(object):
+class GLFileAssistant:
     '''GLFileAssistant is used to help with file processing.'''
 
     def __init__(self, config: GLConfig, transformers: dict[str, tuple[re.Pattern, str] | None] = {}) -> None:
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index f87ba65109..5cd39f66a3 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -63,7 +63,7 @@ normpath = os.path.normpath
 #===============================================================================
 # Define GLImport class
 #===============================================================================
-class GLImport(object):
+class GLImport:
     '''GLImport class is used to provide methods for --import, --add-import,
     --remove-import and --update actions. This is a high-level class, so
     developers may  have to use lower-level classes to create their own
diff --git a/pygnulib/GLInfo.py b/pygnulib/GLInfo.py
index 4dd8dd6e35..c38977c23e 100644
--- a/pygnulib/GLInfo.py
+++ b/pygnulib/GLInfo.py
@@ -44,7 +44,7 @@ isdir = os.path.isdir
 #===============================================================================
 # Define GLInfo class
 #===============================================================================
-class GLInfo(object):
+class GLInfo:
     '''This class is used to get formatted information about gnulib-tool.
     This information is mainly used in stdout messages, but can be used
     anywhere else. The return values are not the same as for the module,
diff --git a/pygnulib/GLMakefileTable.py b/pygnulib/GLMakefileTable.py
index 6568a19846..7547116f35 100644
--- a/pygnulib/GLMakefileTable.py
+++ b/pygnulib/GLMakefileTable.py
@@ -42,7 +42,7 @@ joinpath = constants.joinpath
 #===============================================================================
 # Define GLMakefileTable class
 #===============================================================================
-class GLMakefileTable(object):
+class GLMakefileTable:
     '''This class is used to edit Makefile and store edits as table.
     When user creates Makefile.am, he may need to use this class.
     The internal representation consists of a list of edits.
diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index bab143892f..1f5d536fe3 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -56,7 +56,7 @@ filter_filelist = constants.filter_filelist
 #===============================================================================
 # Define GLModuleSystem class
 #===============================================================================
-class GLModuleSystem(object):
+class GLModuleSystem:
     '''GLModuleSystem is used to operate with module system using dynamic
     searching and patching.'''
 
@@ -169,7 +169,7 @@ class GLModuleSystem(object):
 #===============================================================================
 # Define GLModule class
 #===============================================================================
-class GLModule(object):
+class GLModule:
     '''GLModule is used to create a module object from the file with the given
     path. GLModule can get all information about module, get its dependencies,
     files, etc.'''
@@ -704,7 +704,7 @@ class GLModule(object):
 #===============================================================================
 # Define GLModuleTable class
 #===============================================================================
-class GLModuleTable(object):
+class GLModuleTable:
     '''GLModuleTable is used to work with the list of the modules.'''
 
     def __init__(self, config: GLConfig, inc_all_direct_tests: bool, inc_all_indirect_tests: bool) -> None:
diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py
index 7ea1404e30..51c6ee3193 100644
--- a/pygnulib/GLTestDir.py
+++ b/pygnulib/GLTestDir.py
@@ -95,7 +95,7 @@ def _patch_test_driver() -> None:
 #===============================================================================
 # Define GLTestDir class
 #===============================================================================
-class GLTestDir(object):
+class GLTestDir:
     '''GLTestDir class is used to create a scratch package with the given
     list of the modules.'''
 
@@ -883,7 +883,7 @@ class GLTestDir(object):
 #===============================================================================
 # Define GLMegaTestDir class
 #===============================================================================
-class GLMegaTestDir(object):
+class GLMegaTestDir:
     '''GLMegaTestDir class is used to create a mega scratch package with the
     given modules one by one and all together.'''
 
-- 
2.44.0


             reply	other threads:[~2024-04-03 10:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03 10:22 Collin Funk [this message]
2024-04-03 23:15 ` gnulib-tool.py: Ignore pylint 'unidiomatic-typecheck' warnings Bruno Haible

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

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

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

  git send-email \
    --in-reply-to=e4cced80-b67b-45ae-82bf-b62a84873cd5@gmail.com \
    --to=collin.funk1@gmail.com \
    --cc=bug-gnulib@gnu.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).