Skip to content

Commit fd91e62

Browse files
committed
Ruff cleanups
1 parent 572a3a3 commit fd91e62

File tree

13 files changed

+45
-51
lines changed

13 files changed

+45
-51
lines changed

src/mss/linux/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any
22

3-
from ..base import MSSBase
4-
from ..exception import ScreenShotError
3+
from mss.base import MSSBase
4+
from mss.exception import ScreenShotError
55

66

77
def MSS(backend: str = "xlib", **kwargs: Any) -> MSSBase:

src/mss/linux/xcb.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from collections.abc import Callable, Generator
3232
from typing import Any
3333

34-
from ..exception import ScreenShotError
34+
from mss.exception import ScreenShotError
3535

3636
# In general, anything global starting with Xcb, XCB_, or xcb_ is a
3737
# reflection of something in XCB with the same name.
@@ -633,6 +633,7 @@ class XcbRandrGetScreenResourcesCurrentReply(Structure):
633633
("pad1", c_uint8 * 8),
634634
)
635635

636+
636637
# The version of the spec that the client was written against.
637638
XCB_RANDR_MAJOR_VERSION = 1
638639
XCB_RANDR_MINOR_VERSION = 6
@@ -734,6 +735,7 @@ class XcbRenderQueryPictFormatsReply(Structure):
734735

735736
# xfixes
736737

738+
737739
class XcbXfixesQueryVersionReply(Structure):
738740
_fields_ = (
739741
("response_type", c_uint8),
@@ -762,6 +764,7 @@ class XcbXfixesGetCursorImageReply(Structure):
762764
("pad1", c_uint8 * 8),
763765
)
764766

767+
765768
# The version of the spec that the client was written against.
766769
XCB_XFIXES_MAJOR_VERSION = 6
767770
XCB_XFIXES_MINOR_VERSION = 0
@@ -1070,9 +1073,13 @@ def xcb_render_query_pict_formats(c: XcbConnection) -> XcbRenderQueryPictFormats
10701073
def xcb_render_query_version(c: XcbConnection) -> XcbRenderQueryVersionReply:
10711074
return render.xcb_render_query_version(c).reply(c)
10721075

1073-
def xcb_xfixes_query_version(c: XcbConnection, client_major_version: c_uint32, client_minor_version: c_uint32) -> XcbXfixesQueryVersionReply:
1076+
1077+
def xcb_xfixes_query_version(
1078+
c: XcbConnection, client_major_version: c_uint32, client_minor_version: c_uint32
1079+
) -> XcbXfixesQueryVersionReply:
10741080
return xfixes.xcb_xfixes_query_version(c, client_major_version, client_minor_version).reply(c)
10751081

1082+
10761083
def xcb_xfixes_get_cursor_image(c: XcbConnection) -> XcbXfixesGetCursorImageReply:
10771084
return xfixes.xcb_xfixes_get_cursor_image(c).reply(c)
10781085

@@ -1276,7 +1283,7 @@ def get_utf8_prop(xcb_conn: XcbConnection, window: XcbWindow, prop_name: str) ->
12761283
def connect(display: str | bytes | None = None) -> tuple[XcbConnection, int]:
12771284
if isinstance(display, str):
12781285
display = display.encode("utf-8")
1279-
1286+
12801287
pref_screen_num = c_int()
12811288
conn_p = libxcb.xcb_connect(display, pref_screen_num)
12821289
if libxcb.xcb_connection_has_error(conn_p) != 0:
@@ -1300,6 +1307,7 @@ def disconnect(conn: XcbConnection) -> None:
13001307

13011308
def main(target_name: str | re.Pattern = "emacs", verbose=True) -> None:
13021309
import re
1310+
13031311
from PIL import Image
13041312

13051313
if not isinstance(target_name, re.Pattern):

src/mss/linux/xgetimage.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
from typing import Any, TYPE_CHECKING
1+
from typing import Any
22

3-
from ..base import MSSBase
4-
from ..exception import ScreenShotError
5-
from ..models import Monitor
6-
from ..screenshot import ScreenShot
3+
from mss.base import MSSBase
4+
from mss.exception import ScreenShotError
5+
from mss.models import Monitor
6+
from mss.screenshot import ScreenShot
77

88
# FIXME: We can't currently import libxcb etc. straight from xcb,
99
# since it will update them when we call initialize, and we won't see
1010
# the changes. I'm going to change initialize's API to address that.
1111
from . import xcb
1212
from .xcb import (
13-
initialize,
13+
XCB_IMAGE_FORMAT_Z_PIXMAP,
14+
XCB_RANDR_MAJOR_VERSION,
15+
XCB_RANDR_MINOR_VERSION,
16+
XCB_XFIXES_MAJOR_VERSION,
17+
XCB_XFIXES_MINOR_VERSION,
1418
connect,
1519
disconnect,
16-
xcb_setup_roots,
17-
xcb_randr_query_version,
20+
initialize,
1821
xcb_get_geometry,
19-
xcb_randr_get_screen_resources_current,
20-
xcb_randr_get_screen_resources_current_crtcs,
21-
xcb_randr_get_crtc_info,
2222
xcb_get_image,
23-
XCB_IMAGE_FORMAT_Z_PIXMAP,
2423
xcb_get_image_data,
25-
xcb_xfixes_query_version,
24+
xcb_randr_get_crtc_info,
25+
xcb_randr_get_screen_resources,
26+
xcb_randr_get_screen_resources_crtcs,
27+
xcb_randr_get_screen_resources_current,
28+
xcb_randr_get_screen_resources_current_crtcs,
29+
xcb_randr_query_version,
30+
xcb_setup_roots,
2631
xcb_xfixes_get_cursor_image,
2732
xcb_xfixes_get_cursor_image_cursor_image,
28-
XCB_RANDR_MAJOR_VERSION,
29-
XCB_RANDR_MINOR_VERSION,
30-
XCB_XFIXES_MAJOR_VERSION,
31-
XCB_XFIXES_MINOR_VERSION,
33+
xcb_xfixes_query_version,
3234
)
3335

34-
3536
SUPPORTED_DEPTHS = {24, 32}
3637
SUPPORTED_BYTES_PER_PIXEL = 32
3738
ALL_PLANES = 0xFFFFFFFF # XCB doesn't define AllPlanes
@@ -183,10 +184,7 @@ def _cursor_impl_check_xfixes(self) -> bool:
183184
# We can work with 2.0 and later, but not sure about the
184185
# actual minimum version we can use. That's ok; everything
185186
# these days is much more modern.
186-
if (reply.major_version, reply.minor_version) < (2, 0):
187-
return False
188-
189-
return True
187+
return not (reply.major_version, reply.minor_version) < (2, 0)
190188

191189
def _cursor_impl(self) -> ScreenShot:
192190
"""Retrieve all cursor data. Pixels have to be RGBx."""

src/tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
Source: https://github.com/BoboTiG/python-mss.
33
"""
44

5+
import os
56
from collections.abc import Callable, Generator
67
from functools import partial
78
from hashlib import sha256
8-
import os
99
from pathlib import Path
1010
from platform import system
1111
from zipfile import ZipFile
@@ -15,6 +15,7 @@
1515
from mss import mss
1616
from mss.base import MSSBase
1717

18+
1819
@pytest.fixture(autouse=True)
1920
def _no_warnings(recwarn: pytest.WarningsRecorder) -> Generator:
2021
"""Fail on warning."""
@@ -53,7 +54,7 @@ def raw() -> bytes:
5354

5455

5556
@pytest.fixture(params=["xlib", "xgetimage"] if system() == "Linux" else ["default"])
56-
def backend(request) -> str:
57+
def backend(request: pytest.FixtureRequest) -> str:
5758
return request.param
5859

5960

src/tests/test_cls_image.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
"""
44

55
from collections.abc import Callable
6-
import os
76
from typing import Any
87

9-
from mss import mss
108
from mss.base import MSSBase
119
from mss.models import Monitor
1210

src/tests/test_find_monitors.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"""
44

55
from collections.abc import Callable
6-
import os
76

8-
from mss import mss
97
from mss.base import MSSBase
108

119

src/tests/test_get_pixels.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
Source: https://github.com/BoboTiG/python-mss.
33
"""
44

5-
from collections.abc import Callable
65
import itertools
7-
import os
6+
from collections.abc import Callable
87

98
import pytest
109

11-
from mss import mss
1210
from mss.base import MSSBase, ScreenShot
1311
from mss.exception import ScreenShotError
1412

src/tests/test_implementation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
from __future__ import annotations
66

7-
from collections.abc import Callable
8-
import os
97
import platform
108
import sys
119
import threading
@@ -24,6 +22,8 @@
2422
from mss.screenshot import ScreenShot
2523

2624
if TYPE_CHECKING: # pragma: nocover
25+
from collections.abc import Callable
26+
2727
from mss.models import Monitor
2828

2929
try:
@@ -93,6 +93,7 @@ def test_factory_unknown_system(backend: str, monkeypatch: pytest.MonkeyPatch) -
9393
error = exc.value.args[0]
9494
assert error == "System 'chuck norris' not (yet?) implemented."
9595

96+
9697
@patch.object(sys, "argv", new=[]) # Prevent side effects while testing
9798
@pytest.mark.parametrize("with_cursor", [False, True])
9899
def test_entry_point(with_cursor: bool, capsys: pytest.CaptureFixture, mss_impl: Callable[..., MSSBase]) -> None:

src/tests/test_issue_220.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def take_screenshot(*, backend: str) -> None:
3333
def create_top_level_win(master: tkinter.Tk, backend: str) -> None: # type: ignore[name-defined]
3434
top_level_win = tkinter.Toplevel(master)
3535

36-
take_screenshot_btn = tkinter.Button(top_level_win, text="Take screenshot", command=partial(take_screenshot, backend=backend))
36+
take_screenshot_btn = tkinter.Button(
37+
top_level_win, text="Take screenshot", command=partial(take_screenshot, backend=backend)
38+
)
3739
take_screenshot_btn.pack()
3840

3941
take_screenshot_btn.invoke()

src/tests/test_save.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
"""
44

55
from collections.abc import Callable
6-
import os.path
76
from datetime import datetime
87
from pathlib import Path
98

109
import pytest
1110

12-
from mss import mss
1311
from mss.base import MSSBase
1412

1513
try:

0 commit comments

Comments
 (0)