]> jfr.im git - irc/weechat/qweechat.git/commitdiff
Fix pylint errors
authorSébastien Helleu <redacted>
Sat, 13 Nov 2021 18:50:33 +0000 (19:50 +0100)
committerSébastien Helleu <redacted>
Sat, 13 Nov 2021 18:50:33 +0000 (19:50 +0100)
13 files changed:
qweechat/about.py
qweechat/buffer.py
qweechat/chat.py
qweechat/config.py
qweechat/connection.py
qweechat/debug.py
qweechat/input.py
qweechat/network.py
qweechat/qweechat.py
qweechat/version.py
qweechat/weechat/color.py
qweechat/weechat/protocol.py
qweechat/weechat/testproto.py

index 5336ac4d3da65c238aa486dd92a54ed6a0afd08a..5faa4c798ad6362bb0df915f8e29f788cf7e42fc 100644 (file)
@@ -20,6 +20,8 @@
 # along with QWeeChat.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+"""About dialog box."""
+
 from PySide6 import QtCore, QtWidgets as QtGui
 
 
index 672135ec3de652d008345017be7857fab2781688..a798205f6176bbc8896bc400e9eea279a66c36bf 100644 (file)
@@ -20,6 +20,8 @@
 # along with QWeeChat.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+"""Management of WeeChat buffers/nicklist."""
+
 from pkg_resources import resource_filename
 
 from PySide6 import QtCore, QtGui, QtWidgets
@@ -68,9 +70,6 @@ class GenericListWidget(QtWidgets.QListWidget):
 class BufferListWidget(GenericListWidget):
     """Widget with list of buffers."""
 
-    def __init__(self, *args):
-        super().__init__(*args)
-
     def switch_prev_buffer(self):
         if self.currentRow() > 0:
             self.setCurrentRow(self.currentRow() - 1)
@@ -148,9 +147,9 @@ class Buffer(QtCore.QObject):
 
     bufferInput = QtCore.Signal(str, str)
 
-    def __init__(self, data={}):
+    def __init__(self, data=None):
         QtCore.QObject.__init__(self)
-        self.data = data
+        self.data = data or {}
         self.nicklist = {}
         self.widget = BufferWidget(display_nicklist=self.data.get('nicklist',
                                                                   0))
@@ -234,12 +233,12 @@ class Buffer(QtCore.QObject):
                     ' ': '',
                     '+': 'yellow',
                 }
-                color = prefix_color.get(nick['prefix'], 'green')
-                if color:
+                col = prefix_color.get(nick['prefix'], 'green')
+                if col:
                     icon = QtGui.QIcon(
                         resource_filename(__name__,
                                           'data/icons/bullet_%s_8x8.png' %
-                                          color))
+                                          col))
                 else:
                     pixmap = QtGui.QPixmap(8, 8)
                     pixmap.fill()
index 3a1e6599c2dbdbde05c7936fbcd8c16d26499303..c5d176e8658036e9fa20faa89784210016a10a25 100644 (file)
@@ -20,6 +20,8 @@
 # along with QWeeChat.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+"""Chat area."""
+
 import datetime
 
 from PySide6 import QtCore, QtWidgets, QtGui
@@ -64,11 +66,11 @@ class ChatTextEdit(QtWidgets.QTextEdit):
 
     def display(self, time, prefix, text, forcecolor=None):
         if time == 0:
-            d = datetime.datetime.now()
+            now = datetime.datetime.now()
         else:
-            d = datetime.datetime.fromtimestamp(float(time))
+            now = datetime.datetime.fromtimestamp(float(time))
         self.setTextColor(QtGui.QColor('#999999'))
-        self.insertPlainText(d.strftime('%H:%M '))
+        self.insertPlainText(now.strftime('%H:%M '))
         prefix = self._color.convert(prefix)
         text = self._color.convert(text)
         if forcecolor:
@@ -136,5 +138,5 @@ class ChatTextEdit(QtWidgets.QTextEdit):
         self._setfont[attr](self._fontvalues[self._font[attr]][attr])
 
     def scroll_bottom(self):
-        bar = self.verticalScrollBar()
-        bar.setValue(bar.maximum())
+        scroll = self.verticalScrollBar()
+        scroll.setValue(scroll.maximum())
index 8fcc90199eb8ec38d65b940fe5065c0812ca407c..63b093941e174194fb204551a89cee4ce7ec4d6a 100644 (file)
@@ -20,6 +20,8 @@
 # along with QWeeChat.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+"""Configuration for QWeeChat."""
+
 import configparser
 import os
 
index c1107f2e4516b838e5037d05f98407a577bad9e9..9a5adbae47886ddef8b5c0f6d88f12e44f54d9cc 100644 (file)
@@ -20,6 +20,8 @@
 # along with QWeeChat.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+"""Connection window."""
+
 from PySide6 import QtGui, QtWidgets
 
 
index 8f083be518d90ec5b9b4f0ea272e786ab3cde0a0..dabcb541fdf0f2b9a3d57d245c806f9751a70163 100644 (file)
@@ -20,6 +20,8 @@
 # along with QWeeChat.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+"""Debug window."""
+
 from PySide6 import QtWidgets
 
 from qweechat.chat import ChatTextEdit
index b408407e32239b6082cd7606be06318e1630f1e7..e84fd27e347b1ced88d2cf44be89ab676ca2c1d6 100644 (file)
@@ -20,6 +20,8 @@
 # along with QWeeChat.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+"""Input line for chat and debug window."""
+
 from PySide6 import QtCore, QtWidgets
 
 
@@ -40,7 +42,7 @@ class InputLineEdit(QtWidgets.QLineEdit):
     def keyPressEvent(self, event):
         key = event.key()
         modifiers = event.modifiers()
-        bar = self.scroll_widget.verticalScrollBar()
+        scroll = self.scroll_widget.verticalScrollBar()
         if modifiers == QtCore.Qt.ControlModifier:
             if key == QtCore.Qt.Key_PageUp:
                 self.bufferSwitchPrev.emit()
@@ -54,19 +56,19 @@ class InputLineEdit(QtWidgets.QLineEdit):
             elif key in (QtCore.Qt.Key_Right, QtCore.Qt.Key_Down):
                 self.bufferSwitchNext.emit()
             elif key == QtCore.Qt.Key_PageUp:
-                bar.setValue(bar.value() - (bar.pageStep() / 10))
+                scroll.setValue(scroll.value() - (scroll.pageStep() / 10))
             elif key == QtCore.Qt.Key_PageDown:
-                bar.setValue(bar.value() + (bar.pageStep() / 10))
+                scroll.setValue(scroll.value() + (scroll.pageStep() / 10))
             elif key == QtCore.Qt.Key_Home:
-                bar.setValue(bar.minimum())
+                scroll.setValue(scroll.minimum())
             elif key == QtCore.Qt.Key_End:
-                bar.setValue(bar.maximum())
+                scroll.setValue(scroll.maximum())
             else:
                 QtWidgets.QLineEdit.keyPressEvent(self, event)
         elif key == QtCore.Qt.Key_PageUp:
-            bar.setValue(bar.value() - bar.pageStep())
+            scroll.setValue(scroll.value() - scroll.pageStep())
         elif key == QtCore.Qt.Key_PageDown:
-            bar.setValue(bar.value() + bar.pageStep())
+            scroll.setValue(scroll.value() + scroll.pageStep())
         elif key == QtCore.Qt.Key_Up:
             self._history_navigate(-1)
         elif key == QtCore.Qt.Key_Down:
index 889c424f8d5d24a8ac2e9159a1993f756677d965..36cfb1b86831d1df9e03c7d0a04c5e97b6fe83a8 100644 (file)
@@ -20,6 +20,8 @@
 # along with QWeeChat.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+"""I/O with WeeChat/relay."""
+
 import struct
 
 from PySide6 import QtCore, QtNetwork
index 2a09696e83f304dc9f088508f90e4e3de517033a..a7581b6d787e2874a68e3c7afecc9a6ca68cfecf 100644 (file)
@@ -62,7 +62,7 @@ class MainWindow(QtWidgets.QMainWindow):
     """Main window."""
 
     def __init__(self, *args):
-        super().__init__()
+        super().__init__(*args)
 
         self.config = config.read()
 
@@ -207,7 +207,7 @@ class MainWindow(QtWidgets.QMainWindow):
         """Save connection configuration."""
         if self.network:
             options = self.network.get_options()
-            for option in options.keys():
+            for option in options:
                 self.config.set('relay', option, options[option])
 
     def debug_display(self, *args, **kwargs):
@@ -550,8 +550,8 @@ def main():
     app.setStyle(QtWidgets.QStyleFactory.create('Cleanlooks'))
     app.setWindowIcon(QtGui.QIcon(
         resource_filename(__name__, 'data/icons/weechat.png')))
-    main = MainWindow()
-    main.show()
+    main_win = MainWindow()
+    main_win.show()
     sys.exit(app.exec_())
 
 
index c15371336026e96071969ffd0478464ace3cf73b..2b8c2e3662ed1a0cffb601210ee5c6c645d4cd20 100644 (file)
 # along with QWeeChat.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+"""Version of QWeeChat."""
+
 VERSION = '0.0.1-dev'
 
 
 def qweechat_version():
+    """Return QWeeChat version."""
     return VERSION
index b11bffcefb0d9fbcea36290811de1f8dc76ba113..23a438a4359146c9776b4e56c87b791a1ad8bd4a 100644 (file)
@@ -20,6 +20,8 @@
 # along with QWeeChat.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+"""Remove/replace colors in WeeChat strings."""
+
 import re
 import logging
 
@@ -86,25 +88,25 @@ class Color():
 
     def _rgb_color(self, index):
         color = TERMINAL_COLORS[index*6:(index*6)+6]
-        r = int(color[0:2], 16) * 0.85
-        g = int(color[2:4], 16) * 0.85
-        b = int(color[4:6], 16) * 0.85
-        return '%02x%02x%02x' % (r, g, b)
+        col_r = int(color[0:2], 16) * 0.85
+        col_g = int(color[2:4], 16) * 0.85
+        col_b = int(color[4:6], 16) * 0.85
+        return '%02x%02x%02x' % (col_r, col_g, col_b)
 
     def _convert_weechat_color(self, color):
         try:
             index = int(color)
             return '\x01(Fr%s)' % self.color_options[index]
-        except:  # noqa: E722
-            log.debug('Error decoding WeeChat color "%s"' % color)
+        except Exception:  # noqa: E722
+            log.debug('Error decoding WeeChat color "%s"', color)
             return ''
 
     def _convert_terminal_color(self, fg_bg, attrs, color):
         try:
             index = int(color)
             return '\x01(%s%s#%s)' % (fg_bg, attrs, self._rgb_color(index))
-        except:  # noqa: E722
-            log.debug('Error decoding terminal color "%s"' % color)
+        except Exception:  # noqa: E722
+            log.debug('Error decoding terminal color "%s"', color)
             return ''
 
     def _convert_color_attr(self, fg_bg, color):
@@ -126,8 +128,8 @@ class Color():
             index = int(color)
             return self._convert_terminal_color(fg_bg, attrs,
                                                 WEECHAT_BASIC_COLORS[index][1])
-        except:  # noqa: E722
-            log.debug('Error decoding color "%s"' % color)
+        except Exception:  # noqa: E722
+            log.debug('Error decoding color "%s"', color)
             return ''
 
     def _attrcode_to_char(self, code):
@@ -145,29 +147,27 @@ class Color():
             if color[1] == 'b':
                 # bar code, ignored
                 return ''
-            elif color[1] == '\x1C':
+            if color[1] == '\x1C':
                 # reset
                 return '\x01(Fr)\x01(Br)'
-            elif color[1] in ('F', 'B'):
+            if color[1] in ('F', 'B'):
                 # foreground or background
                 return self._convert_color_attr(color[1], color[2:])
-            elif color[1] == '*':
+            if color[1] == '*':
                 # foreground with optional background
                 items = color[2:].split(',')
-                s = self._convert_color_attr('F', items[0])
+                str_col = self._convert_color_attr('F', items[0])
                 if len(items) > 1:
-                    s += self._convert_color_attr('B', items[1])
-                return s
-            elif color[1] == '@':
+                    str_col += self._convert_color_attr('B', items[1])
+                return str_col
+            if color[1] == '@':
                 # direct ncurses pair number, ignored
                 return ''
-            elif color[1] == 'E':
+            if color[1] == 'E':
                 # text emphasis, ignored
                 return ''
             if color[1:].isdigit():
                 return self._convert_weechat_color(int(color[1:]))
-            # color code
-            pass
         elif color[0] == '\x1A':
             # set attribute
             return '\x01(+%s)' % self._attrcode_to_char(color[1])
@@ -191,8 +191,7 @@ class Color():
             return ''
         if self.debug:
             return RE_COLOR.sub(self._convert_color_debug, text)
-        else:
-            return RE_COLOR.sub(self._convert_color, text)
+        return RE_COLOR.sub(self._convert_color, text)
 
 
 def remove(text):
index 4e1514da8814e1d5b1d64e6c40c2c053c9b84be5..e75119327f744140c2b948db560507d66f30cfd8 100644 (file)
@@ -30,6 +30,8 @@
 #     start dev
 #
 
+"""Decode binary messages received from WeeChat/relay."""
+
 import collections
 import struct
 import zlib
@@ -49,10 +51,10 @@ class WeechatObject:
         self.indent = '  ' if separator == '\n' else ''
         self.separator1 = '\n%s' % self.indent if separator == '\n' else ''
 
-    def _str_value(self, v):
-        if type(v) is str and v is not None:
-            return '\'%s\'' % v
-        return str(v)
+    def _str_value(self, val):
+        if isinstance(val, str) and val is not None:
+            return '\'%s\'' % val
+        return str(val)
 
     def _str_value_hdata(self):
         lines = ['%skeys: %s%s%spath: %s' % (self.separator1,
@@ -84,17 +86,17 @@ class WeechatObject:
         return self._str_value(self.value)
 
     def __str__(self):
-        self._obj_cb = {
+        obj_cb = {
             'hda': self._str_value_hdata,
             'inl': self._str_value_infolist,
         }
         return '%s: %s' % (self.objtype,
-                           self._obj_cb.get(self.objtype,
-                                            self._str_value_other)())
+                           obj_cb.get(self.objtype, self._str_value_other)())
 
 
 class WeechatObjects(list):
     def __init__(self, separator='\n'):
+        super().__init__()
         self.separator = separator
 
     def __str__(self):
@@ -117,16 +119,16 @@ class WeechatMessage:
                 self.size, self.size_uncompressed,
                 100 - ((self.size * 100) // self.size_uncompressed),
                 self.msgid, self.objects)
-        else:
-            return 'size: %d, id=\'%s\', objects:\n%s' % (self.size,
-                                                          self.msgid,
-                                                          self.objects)
+        return 'size: %d, id=\'%s\', objects:\n%s' % (self.size,
+                                                      self.msgid,
+                                                      self.objects)
 
 
 class Protocol:
     """Decode binary message received from WeeChat/relay."""
 
     def __init__(self):
+        self.data = ''
         self._obj_cb = {
             'chr': self._obj_char,
             'int': self._obj_int,
@@ -349,7 +351,7 @@ def hex_and_ascii(data, bytes_per_line=10):
                 char = b'x'
             byte = struct.unpack('B', char)[0]
             str_hex.append(b'%02X' % int(byte))
-            if byte >= 32 and byte <= 127:
+            if 32 <= byte <= 127:
                 str_ascii.append(char)
             else:
                 str_ascii.append(b'.')
index 76a7aed381c1b59dcae2e7991704f38b3be239d4..53f70c54c074a56820635fb90ac676b851c80a0c 100644 (file)
@@ -20,9 +20,7 @@
 # along with QWeeChat.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-"""
-Command-line program for testing WeeChat/relay protocol.
-"""
+"""Command-line program for testing WeeChat/relay protocol."""
 
 import argparse
 import os
@@ -81,7 +79,7 @@ class TestProto(object):
                 self.sock.sendall(msg + b'\n')
                 sys.stdout.write(
                     (b'\x1b[33m<-- ' + msg + b'\x1b[0m\n').decode())
-        except:  # noqa: E722
+        except Exception:  # noqa: E722
             traceback.print_exc()
             print('Failed to send message')
             return False
@@ -106,7 +104,7 @@ class TestProto(object):
                                 protocol.hex_and_ascii(msgd.uncompressed, 20)))
             # display decoded message
             print('\x1b[32m--> {0}\x1b[0m'.format(msgd))
-        except:  # noqa: E722
+        except Exception:  # noqa: E722
             traceback.print_exc()
             print('Error while decoding message from WeeChat')
             return False
@@ -183,7 +181,7 @@ class TestProto(object):
                                     recvbuf = b''
                             sys.stdout.write((prompt + message).decode())
                             sys.stdout.flush()
-        except:  # noqa: E722
+        except Exception:  # noqa: E722
             traceback.print_exc()
             self.send(b'quit')
         return 0