From 6ce87d44a66df9f48b61751902bebf9da0710010 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 6 Dec 2022 12:02:27 -0500 Subject: [PATCH] ci: [pre-commit.ci] autoupdate (#146) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ci: [pre-commit.ci] autoupdate updates: - [github.com/charliermarsh/ruff-pre-commit: v0.0.149 → v0.0.161](https://github.com/charliermarsh/ruff-pre-commit/compare/v0.0.149...v0.0.161) * fix: fix linting * style: add docstyle * style: formatting Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Talley Lambert --- .pre-commit-config.yaml | 2 +- docs/_macros.py | 2 +- examples/qcollapsible.py | 2 +- examples/throttler_demo.py | 2 +- pyproject.toml | 11 +++++------ src/superqt/collapsible/_collapsible.py | 11 ++++++----- src/superqt/fonticon/_iconfont.py | 7 ++++--- src/superqt/fonticon/_qfont_icon.py | 10 ++++++---- src/superqt/sliders/_labeled.py | 3 ++- src/superqt/spinbox/_quantity.py | 7 +++++-- src/superqt/utils/_code_syntax_highlight.py | 1 + src/superqt/utils/_throttler.py | 2 -- 12 files changed, 33 insertions(+), 27 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c20a4f0..53c9298 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: - id: black - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.149 + rev: v0.0.165 hooks: - id: ruff args: ["--fix"] diff --git a/docs/_macros.py b/docs/_macros.py index 7a49c84..93ef2b7 100644 --- a/docs/_macros.py +++ b/docs/_macros.py @@ -37,7 +37,7 @@ def define_env(env: "MacrosPlugin"): ) src = src.replace("app.exec_()", "") - exec(src) + exec(src) # noqa: S102 _grab(dest, width) return ( f"![{page.title}](../{dest.parent.name}/{dest.name})" diff --git a/examples/qcollapsible.py b/examples/qcollapsible.py index 8678e0f..de73b5c 100644 --- a/examples/qcollapsible.py +++ b/examples/qcollapsible.py @@ -1,4 +1,4 @@ -"""Example for QCollapsible""" +"""Example for QCollapsible.""" from qtpy.QtWidgets import QApplication, QLabel, QPushButton from superqt import QCollapsible diff --git a/examples/throttler_demo.py b/examples/throttler_demo.py index 99badc0..2b99b76 100644 --- a/examples/throttler_demo.py +++ b/examples/throttler_demo.py @@ -1,4 +1,4 @@ -"""Adapted for python from the KDToolBox +"""Adapted for python from the KDToolBox. https://github.com/KDAB/KDToolBox/tree/master/qt/KDSignalThrottler diff --git a/pyproject.toml b/pyproject.toml index 8a4815f..e927414 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,16 +101,15 @@ src = ["src","tests"] extend-select = [ "E", # style errors "F", # flakes - # "D", # pydocstyle - "I001", # isort + "D", # pydocstyle + "I", # isort "U", # pyupgrade # "N", # pep8-naming - # "S", # bandit + "S", # bandit "C", # flake8-comprehensions "B", # flake8-bugbear "A001", # flake8-builtins "RUF", # ruff-specific rules - "M001", # Unused noqa directive ] extend-ignore = [ "D100", # Missing docstring in public module @@ -125,9 +124,9 @@ extend-ignore = [ [tool.ruff.per-file-ignores] -"tests/*.py" = ["D"] +"tests/*.py" = ["D", "S101"] "examples/demo_widget.py" = ["E501"] -"examples/*.py" = ["B"] +"examples/*.py" = ["B", "D"] # https://docs.pytest.org/en/6.2.x/customize.html [tool.pytest.ini_options] diff --git a/src/superqt/collapsible/_collapsible.py b/src/superqt/collapsible/_collapsible.py index 7fb19e5..c684c58 100644 --- a/src/superqt/collapsible/_collapsible.py +++ b/src/superqt/collapsible/_collapsible.py @@ -128,7 +128,7 @@ class QCollapsible(QFrame): self._animation.setDuration(msecs) def setEasingCurve(self, easing: QEasingCurve) -> None: - """Set the easing curve for the collapse/expand animation""" + """Set the easing curve for the collapse/expand animation.""" self._animation.setEasingCurve(easing) def addWidget(self, widget: QWidget) -> None: @@ -142,11 +142,11 @@ class QCollapsible(QFrame): widget.removeEventFilter(self) def expand(self, animate: bool = True) -> None: - """Expand (show) the collapsible section""" + """Expand (show) the collapsible section.""" self._expand_collapse(QPropertyAnimation.Direction.Forward, animate) def collapse(self, animate: bool = True) -> None: - """Collapse (hide) the collapsible section""" + """Collapse (hide) the collapsible section.""" self._expand_collapse(QPropertyAnimation.Direction.Backward, animate) def isExpanded(self) -> bool: @@ -154,7 +154,7 @@ class QCollapsible(QFrame): return self._toggle_btn.isChecked() def setLocked(self, locked: bool = True) -> None: - """Set whether collapse/expand is disabled""" + """Set whether collapse/expand is disabled.""" self._locked = locked self._toggle_btn.setCheckable(not locked) @@ -172,7 +172,8 @@ class QCollapsible(QFrame): An emit flag is included so that the toggle signal is only called once (it was being emitted a few times via eventFilter when the widget was expanding - previously).""" + previously). + """ if self._locked: return diff --git a/src/superqt/fonticon/_iconfont.py b/src/superqt/fonticon/_iconfont.py index 33a5391..639253f 100644 --- a/src/superqt/fonticon/_iconfont.py +++ b/src/superqt/fonticon/_iconfont.py @@ -72,9 +72,10 @@ class IconFont(metaclass=IconFontMeta): def namespace2font(namespace: Union[Mapping, Type], name: str) -> Type[IconFont]: """Convenience to convert a namespace (class, module, dict) into an IconFont.""" if isinstance(namespace, type): - assert isinstance( - getattr(namespace, FONTFILE_ATTR), str - ), "Not a valid font type" + if not isinstance(getattr(namespace, FONTFILE_ATTR), str): + raise TypeError( + f"Invalid Font: must declare {FONTFILE_ATTR!r} attribute or classmethod" + ) return namespace elif hasattr(namespace, "__dict__"): ns = dict(namespace.__dict__) diff --git a/src/superqt/fonticon/_qfont_icon.py b/src/superqt/fonticon/_qfont_icon.py index 3884f7c..03f463f 100644 --- a/src/superqt/fonticon/_qfont_icon.py +++ b/src/superqt/fonticon/_qfont_icon.py @@ -23,7 +23,8 @@ from qtpy.QtGui import ( from qtpy.QtWidgets import QApplication, QStyleOption, QWidget from typing_extensions import TypedDict -from ..utils import QMessageHandler +from superqt.utils import QMessageHandler + from ._animations import Animation @@ -45,8 +46,8 @@ ValidColor = Union[ int, str, Qt.GlobalColor, - Tuple[int, int, int, int], # noqa: U006 - Tuple[int, int, int], # noqa: U006 + Tuple[int, int, int, int], + Tuple[int, int, int], None, ] @@ -571,5 +572,6 @@ def _ensure_identifier(name: str) -> str: # replace dashes and spaces with underscores name = name.replace("-", "_").replace(" ", "_") - assert str.isidentifier(name), f"Could not canonicalize name: {name}" + if not str.isidentifier(name): + raise ValueError(f"Could not canonicalize name: {name!r}. (not an identifier)") return name diff --git a/src/superqt/sliders/_labeled.py b/src/superqt/sliders/_labeled.py index ac203cb..17b7747 100644 --- a/src/superqt/sliders/_labeled.py +++ b/src/superqt/sliders/_labeled.py @@ -17,7 +17,8 @@ from qtpy.QtWidgets import ( QWidget, ) -from ..utils import signals_blocked +from superqt.utils import signals_blocked + from ._sliders import QDoubleRangeSlider, QDoubleSlider, QRangeSlider diff --git a/src/superqt/spinbox/_quantity.py b/src/superqt/spinbox/_quantity.py index fc50b3c..8fef9e6 100644 --- a/src/superqt/spinbox/_quantity.py +++ b/src/superqt/spinbox/_quantity.py @@ -11,7 +11,7 @@ except ImportError as e: from qtpy.QtCore import Signal from qtpy.QtWidgets import QComboBox, QDoubleSpinBox, QHBoxLayout, QSizePolicy, QWidget -from ..utils import signals_blocked +from superqt.utils import signals_blocked if TYPE_CHECKING: from decimal import Decimal @@ -78,7 +78,10 @@ class QQuantity(QWidget): if ureg is None: ureg = value._REGISTRY if isinstance(value, Quantity) else UREG else: - assert isinstance(ureg, UnitRegistry) + if not isinstance(ureg, UnitRegistry): + raise TypeError( + f"ureg must be a pint.UnitRegistry, not {type(ureg).__name__}" + ) self._ureg = ureg self._value: Quantity = self._ureg.Quantity(value, units=units) diff --git a/src/superqt/utils/_code_syntax_highlight.py b/src/superqt/utils/_code_syntax_highlight.py index cfd7d79..3cf7763 100644 --- a/src/superqt/utils/_code_syntax_highlight.py +++ b/src/superqt/utils/_code_syntax_highlight.py @@ -6,6 +6,7 @@ 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/_throttler.py b/src/superqt/utils/_throttler.py index a4f5181..e9e4bd1 100644 --- a/src/superqt/utils/_throttler.py +++ b/src/superqt/utils/_throttler.py @@ -133,8 +133,6 @@ class GenericSignalThrottler(QObject): elif self._kind is Kind.Debouncer: self._timer.start() # restart - assert self._timer.isActive() - def cancel(self) -> None: """Cancel any pending emissions.""" self._hasPendingEmission = False