diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 53c9298..6ead559 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,23 +12,23 @@ repos: - id: trailing-whitespace - repo: https://github.com/psf/black - rev: 22.10.0 + rev: 23.1.0 hooks: - id: black - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.165 + rev: v0.0.254 hooks: - id: ruff args: ["--fix"] - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.10.1 + rev: v0.12.1 hooks: - id: validate-pyproject - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.991 + rev: v1.1.1 hooks: - id: mypy exclude: tests|examples diff --git a/docs/_macros.py b/docs/_macros.py index 93ef2b7..1469371 100644 --- a/docs/_macros.py +++ b/docs/_macros.py @@ -104,7 +104,6 @@ def define_env(env: "MacrosPlugin"): out += f"- `{m.name}`\n\n" if self_members: - out += dedent( f""" ## Methods diff --git a/examples/demo_widget.py b/examples/demo_widget.py index 7c0041d..1fa46a9 100644 --- a/examples/demo_widget.py +++ b/examples/demo_widget.py @@ -110,7 +110,6 @@ class DemoWidget(QtW.QWidget): if __name__ == "__main__": - import sys from pathlib import Path diff --git a/examples/icon_explorer.py b/examples/icon_explorer.py index 4f44a89..e50e896 100644 --- a/examples/icon_explorer.py +++ b/examples/icon_explorer.py @@ -369,7 +369,6 @@ class MainWindow(QtWidgets.QMainWindow): if __name__ == "__main__": - import sys app = QtWidgets.QApplication(sys.argv) diff --git a/pyproject.toml b/pyproject.toml index e927414..7de6988 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -98,25 +98,27 @@ src_paths = ["src/superqt", "tests"] line-length = 88 target-version = "py37" src = ["src","tests"] -extend-select = [ +select = [ "E", # style errors "F", # flakes "D", # pydocstyle "I", # isort - "U", # pyupgrade - # "N", # pep8-naming + "UP", # pyupgrade "S", # bandit "C", # flake8-comprehensions "B", # flake8-bugbear "A001", # flake8-builtins "RUF", # ruff-specific rules ] -extend-ignore = [ +ignore = [ "D100", # Missing docstring in public module + "D101", # Missing docstring in public class + "D104", # Missing docstring in public package "D107", # Missing docstring in __init__ "D203", # 1 blank line required before class docstring "D212", # Multi-line docstring summary should start at the first line "D213", # Multi-line docstring summary should start at the second line + "D401", # First line should be in imperative mood "D413", # Missing blank line after last section "D416", # Section name should end with a colon "C901", # Function is too complex diff --git a/src/superqt/combobox/_enum_combobox.py b/src/superqt/combobox/_enum_combobox.py index 7243673..211f0c6 100644 --- a/src/superqt/combobox/_enum_combobox.py +++ b/src/superqt/combobox/_enum_combobox.py @@ -52,11 +52,11 @@ class QEnumComboBox(QComboBox): super().addItems(list(map(_get_name, self._enum_class.__members__.values()))) def enumClass(self) -> Optional[EnumMeta]: - """return current Enum class.""" + """Return current Enum class.""" return self._enum_class def isOptional(self) -> bool: - """return if current enum is with optional annotation.""" + """Return if current enum is with optional annotation.""" return self._allow_none def clear(self): diff --git a/src/superqt/fonticon/_plugins.py b/src/superqt/fonticon/_plugins.py index 8d73853..e649a4b 100644 --- a/src/superqt/fonticon/_plugins.py +++ b/src/superqt/fonticon/_plugins.py @@ -1,3 +1,4 @@ +import contextlib from typing import Dict, List, Set, Tuple from ._iconfont import IconFontMeta, namespace2font @@ -9,7 +10,6 @@ except ImportError: class FontIconManager: - ENTRY_POINT = "superqt.fonticon" _PLUGINS: Dict[str, EntryPoint] = {} _LOADED: Dict[str, IconFontMeta] = {} @@ -98,10 +98,8 @@ def loaded(load_all=False) -> Dict[str, List[str]]: if load_all: discover() for x in available(): - try: + with contextlib.suppress(Exception): _manager._get_font_class(x) - except Exception: - continue return { key: sorted(filter(lambda x: not x.startswith("_"), cls.__dict__)) for key, cls in _manager._LOADED.items() diff --git a/src/superqt/fonticon/_qfont_icon.py b/src/superqt/fonticon/_qfont_icon.py index 8551b2e..15328a1 100644 --- a/src/superqt/fonticon/_qfont_icon.py +++ b/src/superqt/fonticon/_qfont_icon.py @@ -345,7 +345,6 @@ class QFontIcon(QIcon): class QFontIconStore(QObject): - # map of key -> (font_family, font_style) _LOADED_KEYS: dict[str, tuple[str, str]] = {} @@ -398,7 +397,7 @@ class QFontIconStore(QObject): @classmethod def _ensure_char(cls, char: str, family: str, style: str) -> str: - """make sure that `char` is a glyph provided by `family` and `style`.""" + """Make sure that `char` is a glyph provided by `family` and `style`.""" if len(char) == 1 and ord(char) > 256: return char try: @@ -432,7 +431,7 @@ class QFontIconStore(QObject): def addFont( cls, filepath: str, prefix: str, charmap: dict[str, str] | None = None ) -> tuple[str, str] | None: - """Add font at `filepath` to the registry under `key`. + r"""Add font at `filepath` to the registry under `key`. If you'd like to later use a fontkey in the form of `key.some-name`, then `charmap` must be provided and provide a mapping for all of the glyph names @@ -477,7 +476,7 @@ class QFontIconStore(QObject): family: str = families[0] # in Qt6, everything becomes a static member - QFd: QFontDatabase | "type[QFontDatabase]" = ( + QFd: QFontDatabase | type[QFontDatabase] = ( QFontDatabase() if tuple(cast(str, QT_VERSION).split(".")) < ("6", "0") else QFontDatabase diff --git a/src/superqt/qtcompat/__init__.py b/src/superqt/qtcompat/__init__.py index 52141e4..69413d9 100644 --- a/src/superqt/qtcompat/__init__.py +++ b/src/superqt/qtcompat/__init__.py @@ -13,6 +13,7 @@ warnings.warn( # forward any requests for superqt.qtcompat.* to qtpy.* class SuperQtImporter(abc.MetaPathFinder): def find_spec(self, fullname: str, path, target=None): # type: ignore + """Forward any requests for superqt.qtcompat.* to qtpy.*.""" if fullname.startswith(__name__): return util.find_spec(fullname.replace(__name__, "qtpy")) diff --git a/src/superqt/sliders/_generic_slider.py b/src/superqt/sliders/_generic_slider.py index e9b7e15..2535bfd 100644 --- a/src/superqt/sliders/_generic_slider.py +++ b/src/superqt/sliders/_generic_slider.py @@ -66,7 +66,6 @@ class _GenericSlider(QSlider, Generic[_T]): MAX_DISPLAY = 5000 def __init__(self, *args, **kwargs) -> None: - self._minimum = 0.0 self._maximum = 99.0 self._pageStep = 10.0 @@ -276,7 +275,6 @@ class _GenericSlider(QSlider, Generic[_T]): self.update() def wheelEvent(self, e: QtGui.QWheelEvent) -> None: - e.ignore() vertical = bool(e.angleDelta().y()) delta = e.angleDelta().y() if vertical else e.angleDelta().x() diff --git a/src/superqt/sliders/_labeled.py b/src/superqt/sliders/_labeled.py index 17b7747..5fafaa2 100644 --- a/src/superqt/sliders/_labeled.py +++ b/src/superqt/sliders/_labeled.py @@ -1,3 +1,4 @@ +import contextlib from enum import IntEnum from functools import partial from typing import Any @@ -566,10 +567,8 @@ class SliderLabel(QDoubleSpinBox): if opt == EdgeLabelMode.LabelIsRange: self.setMinimum(-9999999) self.setMaximum(9999999) - try: + with contextlib.suppress(Exception): self._slider.rangeChanged.disconnect(self.setRange) - except Exception: - pass else: self.setMinimum(self._slider.minimum()) self.setMaximum(self._slider.maximum()) diff --git a/src/superqt/sliders/_range_style.py b/src/superqt/sliders/_range_style.py index a03af72..c33a59a 100644 --- a/src/superqt/sliders/_range_style.py +++ b/src/superqt/sliders/_range_style.py @@ -260,7 +260,6 @@ def parse_color(color: str, default_attr) -> QColor | QGradient: def update_styles_from_stylesheet(obj: _GenericRangeSlider): - qss: str = obj.styleSheet() parent = obj.parent() diff --git a/src/superqt/utils/_code_syntax_highlight.py b/src/superqt/utils/_code_syntax_highlight.py index f4f1259..9aa1646 100644 --- a/src/superqt/utils/_code_syntax_highlight.py +++ b/src/superqt/utils/_code_syntax_highlight.py @@ -6,7 +6,6 @@ from pygments.lexers import find_lexer_class, get_lexer_by_name from pygments.util import ClassNotFound from qtpy import QtGui - # inspired by https://github.com/Vector35/snippets/blob/master/QCodeEditor.py # (MIT license) and # https://pygments.org/docs/formatterdevelopment/#html-3-2-formatter diff --git a/src/superqt/utils/_qthreading.py b/src/superqt/utils/_qthreading.py index f6e6b77..4559012 100644 --- a/src/superqt/utils/_qthreading.py +++ b/src/superqt/utils/_qthreading.py @@ -64,7 +64,6 @@ def as_generator_function( class WorkerBaseSignals(QObject): - started = Signal() # emitted when the work is started finished = Signal() # emitted when the work is finished _finished = Signal(object) # emitted when the work is finished to delete @@ -358,7 +357,6 @@ class FunctionWorker(WorkerBase[_R]): class GeneratorWorkerSignals(WorkerBaseSignals): - yielded = Signal(object) # emitted with yielded values (if generator used) paused = Signal() # emitted when a running job has successfully paused resumed = Signal() # emitted when a paused job has successfully resumed diff --git a/src/superqt/utils/_throttler.py b/src/superqt/utils/_throttler.py index e9e4bd1..4cd7513 100644 --- a/src/superqt/utils/_throttler.py +++ b/src/superqt/utils/_throttler.py @@ -62,7 +62,6 @@ class EmissionPolicy(IntFlag): class GenericSignalThrottler(QObject): - triggered = Signal() timeoutChanged = Signal(int) timerTypeChanged = Signal(Qt.TimerType) diff --git a/tests/test_fonticon/test_plugins.py b/tests/test_fonticon/test_plugins.py index 267b896..ca8edea 100644 --- a/tests/test_fonticon/test_plugins.py +++ b/tests/test_fonticon/test_plugins.py @@ -12,7 +12,7 @@ FIXTURES = Path(__file__).parent / "fixtures" @pytest.fixture def plugin_store(qapp, monkeypatch): - _path = [str(FIXTURES)] + sys.path.copy() + _path = [str(FIXTURES), *sys.path.copy()] store = QFontIconStore().instance() with monkeypatch.context() as m: m.setattr(sys, "path", _path) diff --git a/tests/test_sliders/test_generic_slider.py b/tests/test_sliders/test_generic_slider.py index 2acd9bf..aae7ecc 100644 --- a/tests/test_sliders/test_generic_slider.py +++ b/tests/test_sliders/test_generic_slider.py @@ -116,7 +116,6 @@ def test_press_move_release(gslider: _GenericSlider, qtbot): @skip_on_linux_qt6 def test_hover(gslider: _GenericSlider): - # stub opt = QStyleOptionSlider() gslider.initStyleOption(opt) diff --git a/tests/test_sliders/test_single_value_sliders.py b/tests/test_sliders/test_single_value_sliders.py index 437f832..e3738fe 100644 --- a/tests/test_sliders/test_single_value_sliders.py +++ b/tests/test_sliders/test_single_value_sliders.py @@ -154,7 +154,6 @@ def test_press_move_release(sld: _GenericSlider, qtbot): @skip_on_linux_qt6 def test_hover(sld: _GenericSlider): - _real_sld = getattr(sld, "_slider", sld) opt = QStyleOptionSlider() @@ -179,7 +178,6 @@ def test_hover(sld: _GenericSlider): def test_wheel(sld: _GenericSlider, qtbot): - if type(sld) is QLabeledSlider and QT_VERSION < (5, 12): pytest.skip() @@ -200,7 +198,6 @@ def test_position(sld: _GenericSlider, qtbot): def test_steps(sld: _GenericSlider, qtbot): - sld.setSingleStep(11) assert sld.singleStep() == 11 @@ -208,7 +205,6 @@ def test_steps(sld: _GenericSlider, qtbot): assert sld.pageStep() == 16 if type(sld) is not QLabeledSlider: - sld.setSingleStep(0.1) assert sld.singleStep() == 0.1 diff --git a/tox.ini b/tox.ini index e61104d..ead7aaf 100644 --- a/tox.ini +++ b/tox.ini @@ -46,7 +46,11 @@ platform = macos: darwin linux: linux windows: win32 -passenv = CI GITHUB_ACTIONS DISPLAY XAUTHORITY +passenv = + CI + GITHUB_ACTIONS + DISPLAY + XAUTHORITY deps = pyqt512: pyqt5==5.12.* pyside512: pyside2==5.12.*