update pre-commit (#151)

This commit is contained in:
Talley Lambert
2023-03-27 12:57:58 -04:00
committed by GitHub
parent a39b467563
commit 183899c4e7
19 changed files with 26 additions and 38 deletions

View File

@@ -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

View File

@@ -104,7 +104,6 @@ def define_env(env: "MacrosPlugin"):
out += f"- `{m.name}`\n\n"
if self_members:
out += dedent(
f"""
## Methods

View File

@@ -110,7 +110,6 @@ class DemoWidget(QtW.QWidget):
if __name__ == "__main__":
import sys
from pathlib import Path

View File

@@ -369,7 +369,6 @@ class MainWindow(QtWidgets.QMainWindow):
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)

View File

@@ -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

View File

@@ -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):

View File

@@ -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()

View File

@@ -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

View File

@@ -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"))

View File

@@ -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()

View File

@@ -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())

View File

@@ -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()

View File

@@ -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

View File

@@ -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

View File

@@ -62,7 +62,6 @@ class EmissionPolicy(IntFlag):
class GenericSignalThrottler(QObject):
triggered = Signal()
timeoutChanged = Signal(int)
timerTypeChanged = Signal(Qt.TimerType)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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.*