From 1fe88536084e1cec259ef59779e71670b646f5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 13 Nov 2021 19:50:33 +0100 Subject: [PATCH] Fix pylint errors --- qweechat/about.py | 2 ++ qweechat/buffer.py | 15 ++++++------ qweechat/chat.py | 12 ++++++---- qweechat/config.py | 2 ++ qweechat/connection.py | 2 ++ qweechat/debug.py | 2 ++ qweechat/input.py | 16 +++++++------ qweechat/network.py | 2 ++ qweechat/qweechat.py | 8 +++---- qweechat/version.py | 3 +++ qweechat/weechat/color.py | 43 +++++++++++++++++------------------ qweechat/weechat/protocol.py | 26 +++++++++++---------- qweechat/weechat/testproto.py | 10 ++++---- 13 files changed, 79 insertions(+), 64 deletions(-) diff --git a/qweechat/about.py b/qweechat/about.py index 5336ac4..5faa4c7 100644 --- a/qweechat/about.py +++ b/qweechat/about.py @@ -20,6 +20,8 @@ # along with QWeeChat. If not, see . # +"""About dialog box.""" + from PySide6 import QtCore, QtWidgets as QtGui diff --git a/qweechat/buffer.py b/qweechat/buffer.py index 672135e..a798205 100644 --- a/qweechat/buffer.py +++ b/qweechat/buffer.py @@ -20,6 +20,8 @@ # along with QWeeChat. If not, see . # +"""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() diff --git a/qweechat/chat.py b/qweechat/chat.py index 3a1e659..c5d176e 100644 --- a/qweechat/chat.py +++ b/qweechat/chat.py @@ -20,6 +20,8 @@ # along with QWeeChat. If not, see . # +"""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()) diff --git a/qweechat/config.py b/qweechat/config.py index 8fcc901..63b0939 100644 --- a/qweechat/config.py +++ b/qweechat/config.py @@ -20,6 +20,8 @@ # along with QWeeChat. If not, see . # +"""Configuration for QWeeChat.""" + import configparser import os diff --git a/qweechat/connection.py b/qweechat/connection.py index c1107f2..9a5adba 100644 --- a/qweechat/connection.py +++ b/qweechat/connection.py @@ -20,6 +20,8 @@ # along with QWeeChat. If not, see . # +"""Connection window.""" + from PySide6 import QtGui, QtWidgets diff --git a/qweechat/debug.py b/qweechat/debug.py index 8f083be..dabcb54 100644 --- a/qweechat/debug.py +++ b/qweechat/debug.py @@ -20,6 +20,8 @@ # along with QWeeChat. If not, see . # +"""Debug window.""" + from PySide6 import QtWidgets from qweechat.chat import ChatTextEdit diff --git a/qweechat/input.py b/qweechat/input.py index b408407..e84fd27 100644 --- a/qweechat/input.py +++ b/qweechat/input.py @@ -20,6 +20,8 @@ # along with QWeeChat. If not, see . # +"""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: diff --git a/qweechat/network.py b/qweechat/network.py index 889c424..36cfb1b 100644 --- a/qweechat/network.py +++ b/qweechat/network.py @@ -20,6 +20,8 @@ # along with QWeeChat. If not, see . # +"""I/O with WeeChat/relay.""" + import struct from PySide6 import QtCore, QtNetwork diff --git a/qweechat/qweechat.py b/qweechat/qweechat.py index 2a09696..a7581b6 100644 --- a/qweechat/qweechat.py +++ b/qweechat/qweechat.py @@ -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_()) diff --git a/qweechat/version.py b/qweechat/version.py index c153713..2b8c2e3 100644 --- a/qweechat/version.py +++ b/qweechat/version.py @@ -20,8 +20,11 @@ # along with QWeeChat. If not, see . # +"""Version of QWeeChat.""" + VERSION = '0.0.1-dev' def qweechat_version(): + """Return QWeeChat version.""" return VERSION diff --git a/qweechat/weechat/color.py b/qweechat/weechat/color.py index b11bffc..23a438a 100644 --- a/qweechat/weechat/color.py +++ b/qweechat/weechat/color.py @@ -20,6 +20,8 @@ # along with QWeeChat. If not, see . # +"""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): diff --git a/qweechat/weechat/protocol.py b/qweechat/weechat/protocol.py index 4e1514d..e751193 100644 --- a/qweechat/weechat/protocol.py +++ b/qweechat/weechat/protocol.py @@ -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'.') diff --git a/qweechat/weechat/testproto.py b/qweechat/weechat/testproto.py index 76a7aed..53f70c5 100644 --- a/qweechat/weechat/testproto.py +++ b/qweechat/weechat/testproto.py @@ -20,9 +20,7 @@ # along with QWeeChat. If not, see . # -""" -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