Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

from __future__ import annotations

import sys
import os

Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ select = [
"W", # pycodestyle warnings
"F", # pyflakes
"UP", # pyupgrade
"I002", # missing-required-import
]
ignore = [
"UP031", # printf-string-formatting, not enforced by pyupgrade
"UP032", # f-string, not enforced by pyupgrade
]

[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.pycodestyle]
max-line-length = 120
2 changes: 2 additions & 0 deletions src/pytestqt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

# _version is automatically generated by setuptools_scm
from pytestqt._version import version

Expand Down
6 changes: 4 additions & 2 deletions src/pytestqt/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import functools
import sys
import traceback
Expand Down Expand Up @@ -33,7 +35,7 @@ def capture_exceptions() -> Iterator[CapturedExceptions]:
def _except_hook(
type_: type[BaseException],
value: BaseException,
tback: Optional[TracebackType],
tback: TracebackType | None,
exceptions: CapturedExceptions,
) -> None:
"""Hook functions installed by _QtExceptionCaptureManager"""
Expand All @@ -47,7 +49,7 @@ class _QtExceptionCaptureManager:
"""

def __init__(self) -> None:
self.old_hook: Optional[ExceptHook] = None
self.old_hook: ExceptHook | None = None
self.exceptions: CapturedExceptions = []

def start(self) -> None:
Expand Down
2 changes: 2 additions & 0 deletions src/pytestqt/logging.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from collections import namedtuple
from contextlib import contextmanager
import datetime
Expand Down
2 changes: 2 additions & 0 deletions src/pytestqt/modeltest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#
# $QT_END_LICENSE$

from __future__ import annotations

import enum
import collections

Expand Down
2 changes: 2 additions & 0 deletions src/pytestqt/plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import warnings

import pytest
Expand Down
2 changes: 2 additions & 0 deletions src/pytestqt/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
Based on from https://github.com/epage/PythonUtils.
"""

from __future__ import annotations

from collections import namedtuple, OrderedDict
import os
import sys
Expand Down
41 changes: 21 additions & 20 deletions src/pytestqt/qtbot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from collections.abc import Callable
import contextlib
from types import TracebackType
Expand All @@ -6,7 +8,6 @@
from typing import (
TYPE_CHECKING,
Literal,
Optional,
Any,
cast,
)
Expand Down Expand Up @@ -190,7 +191,7 @@ def __init__(self, request: FixtureRequest) -> None:
self.wait_until = self.waitUntil
self.wait_callback = self.waitCallback

def _should_raise(self, raising_arg: Optional[bool]) -> bool:
def _should_raise(self, raising_arg: bool | None) -> bool:
ini_val = self._request.config.getini("qt_default_raising")

if raising_arg is not None:
Expand All @@ -201,7 +202,7 @@ def _should_raise(self, raising_arg: Optional[bool]) -> bool:
return True

def addWidget(
self, widget: QWidget, *, before_close_func: Optional[BeforeCloseFunc] = None
self, widget: QWidget, *, before_close_func: BeforeCloseFunc | None = None
) -> None:
"""
Adds a widget to be tracked by this bot. This is not required, but will ensure that the
Expand All @@ -222,7 +223,7 @@ def addWidget(

def waitActive(
self, widget: QWidget, *, timeout: int = 5000
) -> "_WaitWidgetContextManager":
) -> _WaitWidgetContextManager:
"""
Context manager that waits for ``timeout`` milliseconds or until the window is active.
If window is not exposed within ``timeout`` milliseconds, raise
Expand Down Expand Up @@ -251,7 +252,7 @@ def waitActive(

def waitExposed(
self, widget: QWidget, *, timeout: int = 5000
) -> "_WaitWidgetContextManager":
) -> _WaitWidgetContextManager:
"""
Context manager that waits for ``timeout`` milliseconds or until the window is exposed.
If the window is not exposed within ``timeout`` milliseconds, raise
Expand Down Expand Up @@ -336,9 +337,9 @@ def waitSignal(
signal: SignalInstance,
*,
timeout: int = 5000,
raising: Optional[bool] = None,
check_params_cb: Optional[CheckParamsCb] = None,
) -> "SignalBlocker":
raising: bool | None = None,
check_params_cb: CheckParamsCb | None = None,
) -> SignalBlocker:
"""
.. versionadded:: 1.2

Expand Down Expand Up @@ -404,10 +405,10 @@ def waitSignals(
signals: list[SignalInstance],
*,
timeout: int = 5000,
raising: Optional[bool] = None,
check_params_cbs: Optional[list[CheckParamsCb]] = None,
raising: bool | None = None,
check_params_cbs: list[CheckParamsCb] | None = None,
order: WaitSignalsOrder = "none",
) -> "MultiSignalBlocker":
) -> MultiSignalBlocker:
"""
.. versionadded:: 1.4

Expand Down Expand Up @@ -526,7 +527,7 @@ def assertNotEmitted(
spy.assert_not_emitted()

def waitUntil(
self, callback: Callable[[], Optional[bool]], *, timeout: int = 5000
self, callback: Callable[[], bool | None], *, timeout: int = 5000
) -> None:
"""
.. versionadded:: 2.0
Expand Down Expand Up @@ -599,8 +600,8 @@ def timed_out():
self.wait(10)

def waitCallback(
self, *, timeout: int = 5000, raising: Optional[bool] = None
) -> "CallbackBlocker":
self, *, timeout: int = 5000, raising: bool | None = None
) -> CallbackBlocker:
"""
.. versionadded:: 3.1

Expand Down Expand Up @@ -642,7 +643,7 @@ def waitCallback(
return blocker

@contextlib.contextmanager
def captureExceptions(self) -> Iterator["CapturedExceptions"]:
def captureExceptions(self) -> Iterator[CapturedExceptions]:
"""
.. versionadded:: 2.1

Expand All @@ -667,7 +668,7 @@ def captureExceptions(self) -> Iterator["CapturedExceptions"]:
yield exceptions

def screenshot(
self, widget: QWidget, suffix: str = "", region: Optional[QRect] = None
self, widget: QWidget, suffix: str = "", region: QRect | None = None
) -> Path:
"""
.. versionadded:: 4.1
Expand Down Expand Up @@ -783,7 +784,7 @@ def _add_widget(
item: pytest.Item,
widget: QWidget,
*,
before_close_func: Optional[BeforeCloseFunc] = None,
before_close_func: BeforeCloseFunc | None = None,
) -> None:
"""
Register a widget into the given pytest item for later closing.
Expand Down Expand Up @@ -849,9 +850,9 @@ def __enter__(self) -> Self:

def __exit__(
self,
exc_type: Optional[type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None:
__tracebackhide__ = True
try:
Expand Down
5 changes: 3 additions & 2 deletions src/pytestqt/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Optional
from __future__ import annotations


import pytest


def get_marker(item: pytest.Item, name: str) -> Optional["pytest.Mark"]:
def get_marker(item: pytest.Item, name: str) -> pytest.Mark | None:
"""Get a marker from a pytest item.

This is here in order to stay compatible with pytest < 3.6 and not produce
Expand Down
2 changes: 2 additions & 0 deletions src/pytestqt/wait_signal.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from collections.abc import Callable
import functools
import dataclasses
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import time

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import weakref

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import sys

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import datetime

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_modeltest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from pytestqt.qt_compat import qt_api
Expand Down
2 changes: 2 additions & 0 deletions tests/test_qtbot_pep8_aliases.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import inspect
from collections.abc import Iterator
from unittest.mock import MagicMock
Expand Down
2 changes: 2 additions & 0 deletions tests/test_qtest_proxies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from pytestqt.qt_compat import qt_api
Expand Down
2 changes: 2 additions & 0 deletions tests/test_screenshot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pathlib

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_wait_signal.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import functools
import fnmatch

Expand Down
9 changes: 5 additions & 4 deletions tests/test_wait_until.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from collections.abc import Callable, Iterator
from typing import Optional

import pytest

Expand Down Expand Up @@ -30,7 +31,7 @@ def ticks(self) -> int:

def test_wait_until(
qtbot: QtBot,
wait_4_ticks_callback: Callable[[], Optional[bool]],
wait_4_ticks_callback: Callable[[], bool | None],
tick_counter: Counter,
) -> None:
tick_counter.start(100)
Expand All @@ -40,7 +41,7 @@ def test_wait_until(

def test_wait_until_timeout(
qtbot: QtBot,
wait_4_ticks_callback: Callable[[], Optional[bool]],
wait_4_ticks_callback: Callable[[], bool | None],
tick_counter: Counter,
) -> None:
tick_counter.start(200)
Expand All @@ -61,7 +62,7 @@ def test_pep8_alias(qtbot: QtBot) -> None:
@pytest.fixture(params=["predicate", "assert"])
def wait_4_ticks_callback(
request: pytest.FixtureRequest, tick_counter: Counter
) -> Callable[[], Optional[bool]]:
) -> Callable[[], bool | None]:
"""Parametrized fixture which returns the two possible callback methods that can be
passed to ``waitUntil``: predicate and assertion.
"""
Expand Down
Loading