[8/9] Suppress some "undefined" warnings from flake8

Message ID 20240319-more-flake8-v1-8-893549dbed75@adacore.com
State New
Headers
Series Make gdb/python flake-clean |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

Tom Tromey March 19, 2024, 5:33 p.m. UTC
  flake8 warns about some identifiers in __init__.py, because it does
not realize these come from the star-imported _gdb module.  This patch
suppresses these warnings.
---
 gdb/python/lib/gdb/__init__.py | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
  

Comments

Simon Marchi March 20, 2024, 6:58 p.m. UTC | #1
On 3/19/24 13:33, Tom Tromey wrote:
> flake8 warns about some identifiers in __init__.py, because it does
> not realize these come from the star-imported _gdb module.  This patch
> suppresses these warnings.
> ---
>  gdb/python/lib/gdb/__init__.py | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
> index 2ff1f95c8fd..cff2f3afa49 100644
> --- a/gdb/python/lib/gdb/__init__.py
> +++ b/gdb/python/lib/gdb/__init__.py
> @@ -56,15 +56,14 @@ class _GdbFile(object):
>              self.write(line)
>  
>      def flush(self):
> -        flush(stream=self.stream)
> +        flush(stream=self.stream)  # noqa: F405

So, this calls _gdb.flush?  I would prefer if those calls were qualified
(not relying on the star import), so that we wouldn't have to guess
where these symbols come from.  Is it possible to do, in addition of
having the star import (needed to re-export stuff)?

Simon
  
Tom Tromey March 20, 2024, 8:30 p.m. UTC | #2
>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:

>> def flush(self):
>> -        flush(stream=self.stream)
>> +        flush(stream=self.stream)  # noqa: F405

Simon> So, this calls _gdb.flush?  I would prefer if those calls were qualified
Simon> (not relying on the star import), so that we wouldn't have to guess
Simon> where these symbols come from.  Is it possible to do, in addition of
Simon> having the star import (needed to re-export stuff)?

Yeah.  I'll send v2 with this fixed.

Tom
  
Tom Tromey March 20, 2024, 8:32 p.m. UTC | #3
Tom> Yeah.  I'll send v2 with this fixed.

Well, I did some branch shenanigans and b4 is unhappy, so here's the
updated version of just this one patch.

Tom

commit 19d1ac05202ade4d4129bbad0e277f67bfdb1aaf
Author: Tom Tromey <tromey@adacore.com>
Date:   Tue Mar 19 11:08:34 2024 -0600

    Suppress some "undefined" warnings from flake8
    
    flake8 warns about some identifiers in __init__.py, because it does
    not realize these come from the star-imported _gdb module.  This patch
    suppresses these warnings.
    
diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
index 2ff1f95c8fd..611d725af58 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -26,6 +26,8 @@ if sys.version_info >= (3, 4):
 else:
     from imp import reload
 
+import _gdb
+
 # Note that two indicators are needed here to silence flake8.
 from _gdb import *  # noqa: F401,F403
 
@@ -56,15 +58,14 @@ class _GdbFile(object):
             self.write(line)
 
     def flush(self):
-        flush(stream=self.stream)
+        _gdb.flush(stream=self.stream)
 
     def write(self, s):
-        write(s, stream=self.stream)
-
+        _gdb.write(s, stream=self.stream)
 
-sys.stdout = _GdbFile(STDOUT)
 
-sys.stderr = _GdbFile(STDERR)
+sys.stdout = _GdbFile(_gdb.STDOUT)
+sys.stderr = _GdbFile(_gdb.STDERR)
 
 # Default prompt hook does nothing.
 prompt_hook = None
@@ -185,7 +186,7 @@ def GdbSetPythonDirectory(dir):
 
 def current_progspace():
     "Return the current Progspace."
-    return selected_inferior().progspace
+    return _gdb.selected_inferior().progspace
 
 
 def objfiles():
@@ -222,14 +223,14 @@ def set_parameter(name, value):
             value = "on"
         else:
             value = "off"
-    execute("set " + name + " " + str(value), to_string=True)
+    _gdb.execute("set " + name + " " + str(value), to_string=True)
 
 
 @contextmanager
 def with_parameter(name, value):
     """Temporarily set the GDB parameter NAME to VALUE.
     Note that this is a context manager."""
-    old_value = parameter(name)
+    old_value = _gdb.parameter(name)
     set_parameter(name, value)
     try:
         # Nothing that useful to return.
  

Patch

diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
index 2ff1f95c8fd..cff2f3afa49 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -56,15 +56,14 @@  class _GdbFile(object):
             self.write(line)
 
     def flush(self):
-        flush(stream=self.stream)
+        flush(stream=self.stream)  # noqa: F405
 
     def write(self, s):
-        write(s, stream=self.stream)
+        write(s, stream=self.stream)  # noqa: F405
 
 
-sys.stdout = _GdbFile(STDOUT)
-
-sys.stderr = _GdbFile(STDERR)
+sys.stdout = _GdbFile(STDOUT)   # noqa: F405
+sys.stderr = _GdbFile(STDERR)   # noqa: F405
 
 # Default prompt hook does nothing.
 prompt_hook = None
@@ -185,7 +184,7 @@  def GdbSetPythonDirectory(dir):
 
 def current_progspace():
     "Return the current Progspace."
-    return selected_inferior().progspace
+    return selected_inferior().progspace  # noqa: F405
 
 
 def objfiles():
@@ -222,14 +221,14 @@  def set_parameter(name, value):
             value = "on"
         else:
             value = "off"
-    execute("set " + name + " " + str(value), to_string=True)
+    execute("set " + name + " " + str(value), to_string=True)  # noqa: F405
 
 
 @contextmanager
 def with_parameter(name, value):
     """Temporarily set the GDB parameter NAME to VALUE.
     Note that this is a context manager."""
-    old_value = parameter(name)
+    old_value = parameter(name)  # noqa: F405
     set_parameter(name, value)
     try:
         # Nothing that useful to return.