Skip to content

Commit

Permalink
more linting and typing
Browse files Browse the repository at this point in the history
  • Loading branch information
MAKOMO committed Oct 18, 2023
1 parent 909131f commit 6abc7a2
Show file tree
Hide file tree
Showing 61 changed files with 1,838 additions and 1,665 deletions.
4 changes: 2 additions & 2 deletions src/artisanlib/acaia.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import logging
from typing import List, Optional, Union, Tuple, Callable
from typing_extensions import Final # Python <=3.7
from typing import Final # Python <=3.7


from artisanlib.ble import UUID, BLE_CHAR_TYPE
Expand Down Expand Up @@ -121,7 +121,7 @@ def resetProtocolParser(self) -> None:
self.protocolParseDataLen = 0
self.protocolParseDataIndex = 0

def acaiaProtocolParser(self, write:Callable[[Optional[bytes]],None], dataIn) -> None:
def acaiaProtocolParser(self, write:Callable[[Optional[bytes]],None], dataIn:bytes) -> None:
for c_in in dataIn:
if self.protocolParseStep==self.E_PRS_CHECKHEADER1:
if c_in == self.HEADER1:
Expand Down
9 changes: 4 additions & 5 deletions src/artisanlib/aillio.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#from lxml import html # unused

import logging
from typing import Optional, TYPE_CHECKING
from typing import Optional, Dict, TYPE_CHECKING
from typing import Final # Python <=3.7

if TYPE_CHECKING:
Expand All @@ -42,7 +42,6 @@
from multiprocessing.connection import Connection # type:ignore # pylint: disable=unused-import
from artisanlib.types import ProfileData # pylint: disable=unused-import
from artisanlib.main import ApplicationWindow # pylint: disable=unused-import
# from PyQt6.QtCore import QUrl # pylint: disable=unused-import

try:
from PyQt6.QtCore import QDateTime, Qt # @UnusedImport @Reimport @UnresolvedImport
Expand Down Expand Up @@ -80,7 +79,7 @@ class AillioR1:
AILLIO_STATE_COOLING = 0x08
AILLIO_STATE_SHUTDOWN = 0x09

def __init__(self, debug=False) -> None:
def __init__(self, debug:bool = False) -> None:
self.simulated = False
self.AILLIO_DEBUG = debug
self.__dbg('init')
Expand Down Expand Up @@ -408,7 +407,7 @@ def __readreply(self, length):
return self.usbhandle.read(self.AILLIO_ENDPOINT_RD, length)
raise OSError('not found or no permission')

def extractProfileBulletDict(data, aw:'ApplicationWindow') -> 'ProfileData':
def extractProfileBulletDict(data:Dict, aw:'ApplicationWindow') -> 'ProfileData':
try:
res:'ProfileData' = {} # the interpreted data set

Expand Down Expand Up @@ -456,7 +455,7 @@ def extractProfileBulletDict(data, aw:'ApplicationWindow') -> 'ProfileData':
try:
if 'weightGreen' in data or 'weightRoasted' in data:
wunit = aw.qmc.weight_units.index(aw.qmc.weight[2])
if wunit in [1,3]: # turn Kg into g, and lb into oz
if wunit in {1,3}: # turn Kg into g, and lb into oz
wunit = wunit -1
wgreen:float = 0
if 'weightGreen' in data:
Expand Down
19 changes: 6 additions & 13 deletions src/artisanlib/alarms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import os
import sys
import logging
from typing import TYPE_CHECKING
from typing import Dict, Union, List, TYPE_CHECKING
from typing import Final # Python <=3.7

if TYPE_CHECKING:
Expand Down Expand Up @@ -674,7 +674,7 @@ def exportalarms(self,_):
def exportalarmsJSON(self,filename):
try:
self.savealarms()
alarms = {}
alarms:Dict[str,Union[List[int],List[float],List[str]]] = {}
alarms['alarmflags'] = self.aw.qmc.alarmflag
alarms['alarmguards'] = self.aw.qmc.alarmguard
alarms['alarmnegguards'] = self.aw.qmc.alarmnegguard
Expand Down Expand Up @@ -717,15 +717,6 @@ def closealarms(self):
def closeEvent(self, _):
self.closealarms()

@pyqtSlot(bool)
def restorealarmsets(self,_):
self.aw.restorealarmsets()
self.setAlarmSetLabels()

@pyqtSlot(bool)
def backupalarmsets(self,_):
self.aw.backupalarmsets()

def savealarms(self):
try:
self.alarmtable.sortItems(0)
Expand Down Expand Up @@ -773,7 +764,7 @@ def savealarms(self):
offset = self.alarmtable.cellWidget(i,5)
assert isinstance(offset, QTimeEdit)
tx = self.aw.QTime2time(offset.time())
self.aw.qmc.alarmoffset[i] = max(0,tx)
self.aw.qmc.alarmoffset[i] = max(0,int(round(tx)))
atype = self.alarmtable.cellWidget(i,6)
assert isinstance(atype, MyQComboBox)
self.aw.qmc.alarmsource[i] = int(str(atype.currentIndex())) - 3
Expand Down Expand Up @@ -962,7 +953,9 @@ def setalarmtablerow(self,i):
if beepL is not None:
item1 = beepL.itemAt(1)
if item1 is not None:
self.alarmtable.setItem(i, 10, MyTableWidgetItemQCheckBox(item1.widget()))
item1widget = item1.widget()
if isinstance(item1widget,QCheckBox):
self.alarmtable.setItem(i, 10, MyTableWidgetItemQCheckBox(item1widget))
self.alarmtable.setCellWidget(i,11,descriptionedit)
self.alarmtable.setItem(i, 11, MyTableWidgetItemQLineEdit(descriptionedit))

Expand Down
2 changes: 1 addition & 1 deletion src/artisanlib/arabic_reshaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def get_lam_alef(candidate_alef, candidate_lam, is_end_of_word):
return ''

class DecomposedWord: # pylint: disable=too-few-public-methods
def __init__(self, word) -> None:
def __init__(self, word:str) -> None:
self.stripped_harakat = []
self.harakat_positions = []
self.stripped_regular_letters = []
Expand Down
6 changes: 4 additions & 2 deletions src/artisanlib/autosave.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@


if TYPE_CHECKING:
from artisanlib.main import ApplicationWindow # noqa: F401 # pylint: disable=unused-import
from PyQt6.QtWidgets import QWidget # pylint: disable=unused-import
from PyQt6.QtGui import QStandardItem # pylint: disable=unused-import

class autosaveDlg(ArtisanDialog):
def __init__(self, parent, aw) -> None:
def __init__(self, parent:'QWidget', aw:'ApplicationWindow') -> None:
super().__init__(parent, aw)
self.setModal(True)
self.setWindowTitle(QApplication.translate('Form Caption','Autosave'))
Expand All @@ -60,7 +62,7 @@ def __init__(self, parent, aw) -> None:
autochecklabel = QLabel(QApplication.translate('CheckBox','Autosave [a]'))
self.autocheckbox = QCheckBox()
self.autocheckbox.setToolTip(QApplication.translate('Tooltip', 'ON/OFF of automatic saving when pressing keyboard letter [a]'))
self.autocheckbox.setChecked(self.aw.qmc.autosaveflag)
self.autocheckbox.setChecked(bool(self.aw.qmc.autosaveflag))

addtorecentfileslabel = QLabel(QApplication.translate('CheckBox','Add to recent file list'))
self.addtorecentfiles = QCheckBox()
Expand Down
18 changes: 10 additions & 8 deletions src/artisanlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import platform
from typing import Optional, TYPE_CHECKING


from artisanlib.util import deltaLabelUTF8, stringfromseconds, stringtoseconds
from artisanlib.dialogs import ArtisanDialog

Expand All @@ -35,10 +36,11 @@
QSpinBox) # type: ignore # @UnusedImport @Reimport @UnresolvedImport

if TYPE_CHECKING:
from PyQt6.QtWidgets import QPushButton # pylint: disable=unused-import
from artisanlib.main import ApplicationWindow # pylint: disable=unused-import
from PyQt6.QtWidgets import QPushButton, QWidget # pylint: disable=unused-import

class WindowsDlg(ArtisanDialog):
def __init__(self, parent, aw) -> None:
def __init__(self, parent:'QWidget', aw:'ApplicationWindow') -> None:
super().__init__(parent, aw)

# remember previous original settings
Expand Down Expand Up @@ -575,7 +577,7 @@ def zlimitChanged(self):
self.autodeltaxETFlag.blockSignals(False)
self.autodeltaxBTFlag.blockSignals(False)
self.aw.qmc.zlimit = new_value
if bool(self.aw.comparator):
if self.aw.comparator is not None:
self.aw.comparator.redraw()
else:
self.aw.qmc.redraw(recomputeAllDeltas=False)
Expand Down Expand Up @@ -603,7 +605,7 @@ def autoDeltaxFlagChanged(self,_):
self.aw.qmc.autodeltaxET = self.autodeltaxETFlag.isChecked()
self.aw.qmc.autodeltaxBT = self.autodeltaxBTFlag.isChecked()
if not self.aw.qmc.flagon and (self.autodeltaxETFlag or self.autodeltaxBTFlag):
if bool(self.aw.comparator):
if self.aw.comparator is not None:
self.aw.comparator.redraw()
self.zlimitEdit.setText(str(self.aw.qmc.zlimit))
else:
Expand All @@ -616,7 +618,7 @@ def autoTimexFlagChanged(self,n):
self.locktimexFlag.setChecked(False)
self.enableAutoControls()
self.enableXAxisControls()
if bool(self.aw.comparator):
if self.aw.comparator is not None:
self.aw.comparator.redraw()
elif not self.aw.qmc.flagon:
self.autoAxis()
Expand Down Expand Up @@ -750,7 +752,7 @@ def changegridstyle(self,_):
@pyqtSlot(int)
def changelegendloc(self,_):
self.aw.qmc.legendloc = self.legendComboBox.currentIndex()
if bool(self.aw.comparator):
if self.aw.comparator is not None:
self.aw.comparator.legend = None
self.aw.comparator.redraw()
else:
Expand All @@ -760,7 +762,7 @@ def changelegendloc(self,_):
@pyqtSlot(int)
def changeAutoTimexMode(self,_):
self.aw.qmc.autotimexMode = self.autotimexModeCombobox.currentIndex()
if bool(self.aw.comparator):
if self.aw.comparator is not None:
self.aw.comparator.modeComboBox.setCurrentIndex(self.aw.qmc.autotimexMode)
elif not self.aw.qmc.flagon:
self.autoAxis()
Expand Down Expand Up @@ -962,7 +964,7 @@ def reset(self,_):
self.zlimitEdit.setText(str(self.aw.qmc.zlimit_C_default))
self.zlimitEdit_min.setText(str(self.aw.qmc.zlimit_min_C_default))
self.zgridSpinBox.setValue(int(self.aw.qmc.zgrid_C_default))
if bool(self.aw.comparator):
if self.aw.comparator is not None:
self.aw.comparator.redraw()
else:
self.aw.qmc.redraw(recomputeAllDeltas=False)
8 changes: 7 additions & 1 deletion src/artisanlib/batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

from artisanlib.dialogs import ArtisanDialog

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from artisanlib.main import ApplicationWindow # pylint: disable=unused-import
from PyQt6.QtWidgets import QWidget # pylint: disable=unused-import

try:
from PyQt6.QtCore import Qt, pyqtSlot, QSettings # @UnusedImport @Reimport @UnresolvedImport
from PyQt6.QtWidgets import (QApplication, QLabel, QHBoxLayout, QVBoxLayout, QCheckBox, # @UnusedImport @Reimport @UnresolvedImport
Expand All @@ -27,7 +33,7 @@
QDialogButtonBox, QGridLayout, QLineEdit, QSpinBox, QLayout) # type: ignore # @UnusedImport @Reimport @UnresolvedImport

class batchDlg(ArtisanDialog):
def __init__(self, parent, aw) -> None:
def __init__(self, parent:'QWidget', aw:'ApplicationWindow') -> None:
super().__init__(parent, aw)
self.setModal(True)
self.setWindowTitle(QApplication.translate('Form Caption','Batch'))
Expand Down
4 changes: 1 addition & 3 deletions src/artisanlib/ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def connectCurrentDevice(self) -> None:
self.deviceDisconnected.emit()

@QtCore.pyqtSlot('QBluetoothDeviceDiscoveryAgent::Error')
def scanError(self, error) -> None: # pylint: disable=no-self-use
def scanError(self, error:QtBluetooth.QBluetoothDeviceDiscoveryAgent.Error) -> None: # pylint: disable=no-self-use
_log.debug('scanError: %s', error)

@QtCore.pyqtSlot()
Expand All @@ -350,8 +350,6 @@ def onScanFinished(self) -> None:
@staticmethod
def deviceHasService(device:QtBluetooth.QBluetoothDeviceInfo, service_uuid:QtBluetooth.QBluetoothUuid) -> bool:
try:
if device is None:
return False
services = device.serviceUuids()
has_service:bool = services is not None and len(services)>0 and service_uuid in services
if has_service:
Expand Down
9 changes: 8 additions & 1 deletion src/artisanlib/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# AUTHOR
# Marko Luther, 2023

from typing import TYPE_CHECKING

from artisanlib.util import fromCtoF, fromFtoC, stringfromseconds, stringtoseconds, comma2dot
from artisanlib.dialogs import ArtisanDialog

Expand All @@ -29,8 +31,13 @@
from PyQt5.QtWidgets import (QApplication, QLabel, QGridLayout, QGroupBox, QLineEdit, # type: ignore # @UnusedImport @Reimport @UnresolvedImport
QComboBox, QHBoxLayout, QVBoxLayout) # type: ignore # @UnusedImport @Reimport @UnresolvedImport


if TYPE_CHECKING:
from artisanlib.main import ApplicationWindow # noqa: F401 # pylint: disable=unused-import
from PyQt6.QtWidgets import QWidget # pylint: disable=unused-import

class calculatorDlg(ArtisanDialog):
def __init__(self, parent, aw) -> None:
def __init__(self, parent:'QWidget', aw:'ApplicationWindow') -> None:
super().__init__(parent, aw)
self.setModal(True)
self.setWindowTitle(QApplication.translate('Form Caption','Roast Calculator'))
Expand Down
Loading

0 comments on commit 6abc7a2

Please sign in to comment.