Skip to content

Commit 38d0395

Browse files
committed
Linux: Fix Mypy errors
1 parent e6d4ca4 commit 38d0395

File tree

1 file changed

+26
-43
lines changed

1 file changed

+26
-43
lines changed

mss/linux.py

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ def _set_cfunctions(self):
235235
See https://tronche.com/gui/x/xlib/function-index.html for details.
236236
"""
237237

238-
def cfactory(attr=self.xlib, func=None, argtypes=None, restype=None):
239-
# type: (Any, str, List[Any], Any) -> None
238+
def cfactory(func, argtypes, restype, attr=self.xlib):
239+
# type: (str, List[Any], Any, Any) -> None
240240
""" Factorize ctypes creations. """
241241
self._cfactory(
242242
attr=attr,
@@ -254,30 +254,18 @@ def cfactory(attr=self.xlib, func=None, argtypes=None, restype=None):
254254
char_p = ctypes.c_char_p
255255
pointer = ctypes.POINTER
256256

257-
cfactory(func="XSetErrorHandler", argtypes=[void], restype=c_int)
257+
cfactory("XSetErrorHandler", [void], c_int)
258+
cfactory("XGetErrorText", [pointer(Display), c_int, char_p, c_int], void)
259+
cfactory("XOpenDisplay", [char_p], pointer(Display))
260+
cfactory("XDefaultRootWindow", [pointer(Display)], pointer(XWindowAttributes))
258261
cfactory(
259-
func="XGetErrorText",
260-
argtypes=[pointer(Display), c_int, char_p, c_int],
261-
restype=void,
262+
"XGetWindowAttributes",
263+
[pointer(Display), pointer(XWindowAttributes), pointer(XWindowAttributes)],
264+
c_int,
262265
)
263-
cfactory(func="XOpenDisplay", argtypes=[char_p], restype=pointer(Display))
264266
cfactory(
265-
func="XDefaultRootWindow",
266-
argtypes=[pointer(Display)],
267-
restype=pointer(XWindowAttributes),
268-
)
269-
cfactory(
270-
func="XGetWindowAttributes",
271-
argtypes=[
272-
pointer(Display),
273-
pointer(XWindowAttributes),
274-
pointer(XWindowAttributes),
275-
],
276-
restype=c_int,
277-
)
278-
cfactory(
279-
func="XGetImage",
280-
argtypes=[
267+
"XGetImage",
268+
[
281269
pointer(Display),
282270
pointer(Display),
283271
c_int,
@@ -287,48 +275,43 @@ def cfactory(attr=self.xlib, func=None, argtypes=None, restype=None):
287275
ulong,
288276
c_int,
289277
],
290-
restype=pointer(XImage),
278+
pointer(XImage),
291279
)
292-
cfactory(func="XDestroyImage", argtypes=[pointer(XImage)], restype=void)
280+
cfactory("XDestroyImage", [pointer(XImage)], void)
293281

294282
# A simple benchmark calling 10 times those 2 functions:
295283
# XRRGetScreenResources(): 0.1755971429956844 s
296284
# XRRGetScreenResourcesCurrent(): 0.0039125580078689 s
297285
# The second is faster by a factor of 44! So try to use it first.
298286
try:
299287
cfactory(
288+
"XRRGetScreenResourcesCurrent",
289+
[pointer(Display), pointer(Display)],
290+
pointer(XRRScreenResources),
300291
attr=self.xrandr,
301-
func="XRRGetScreenResourcesCurrent",
302-
argtypes=[pointer(Display), pointer(Display)],
303-
restype=pointer(XRRScreenResources),
304292
)
305293
except AttributeError:
306294
cfactory(
295+
"XRRGetScreenResources",
296+
[pointer(Display), pointer(Display)],
297+
pointer(XRRScreenResources),
307298
attr=self.xrandr,
308-
func="XRRGetScreenResources",
309-
argtypes=[pointer(Display), pointer(Display)],
310-
restype=pointer(XRRScreenResources),
311299
)
312300
self.xrandr.XRRGetScreenResourcesCurrent = self.xrandr.XRRGetScreenResources
313301

314302
cfactory(
303+
"XRRGetCrtcInfo",
304+
[pointer(Display), pointer(XRRScreenResources), c_long],
305+
pointer(XRRCrtcInfo),
315306
attr=self.xrandr,
316-
func="XRRGetCrtcInfo",
317-
argtypes=[pointer(Display), pointer(XRRScreenResources), c_long],
318-
restype=pointer(XRRCrtcInfo),
319-
)
320-
cfactory(
321-
attr=self.xrandr,
322-
func="XRRFreeScreenResources",
323-
argtypes=[pointer(XRRScreenResources)],
324-
restype=void,
325307
)
326308
cfactory(
309+
"XRRFreeScreenResources",
310+
[pointer(XRRScreenResources)],
311+
void,
327312
attr=self.xrandr,
328-
func="XRRFreeCrtcInfo",
329-
argtypes=[pointer(XRRCrtcInfo)],
330-
restype=void,
331313
)
314+
cfactory("XRRFreeCrtcInfo", [pointer(XRRCrtcInfo)], void, attr=self.xrandr)
332315

333316
def get_error_details(self):
334317
# type: () -> Optional[Dict[str, Any]]

0 commit comments

Comments
 (0)