Skip to content

Commit 7697da9

Browse files
committed
Fix overload and TYPE_CHECKING type comments
1 parent 53bd753 commit 7697da9

7 files changed

Lines changed: 125 additions & 55 deletions

File tree

Xlib/display.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,23 +225,45 @@ def has_extension(self, extension):
225225

226226
if TYPE_CHECKING:
227227
@overload
228-
def create_resource_object(self, type: Literal['resource'], id: int) -> resource.Resource: ...
228+
def create_resource_object(self, type, id):
229+
# type: (Literal['resource'], int) -> resource.Resource
230+
pass
229231
@overload
230-
def create_resource_object(self, type: Literal['drawable'], id: int) -> drawable.Drawable: ...
232+
def create_resource_object(self, type, id):
233+
# type: (Literal['drawable'], int) -> resource.Drawable
234+
pass
231235
@overload
232-
def create_resource_object(self, type: Literal['window'], id: int) -> drawable.Window: ...
236+
def create_resource_object(self, type, id):
237+
# type: (Literal['window'], int) -> resource.Window
238+
pass
233239
@overload
234-
def create_resource_object(self, type: Literal['pixmap'], id: int) -> drawable.Pixmap: ...
240+
def create_resource_object(self, type, id):
241+
# type: (Literal['pixmap'], int) -> resource.Pixmap
242+
pass
235243
@overload
236-
def create_resource_object(self, type: Literal['fontable'], id: int) -> fontable.Fontable: ...
244+
def create_resource_object(self, type, id):
245+
# type: (Literal['fontable'], int) -> resource.Fontable
246+
pass
237247
@overload
238-
def create_resource_object(self, type: Literal['font'], id: int) -> fontable.Font: ...
248+
def create_resource_object(self, type, id):
249+
# type: (Literal['font'], int) -> resource.Font
250+
pass
239251
@overload
240-
def create_resource_object(self, type: Literal['gc'], id: int) -> fontable.GC: ...
252+
def create_resource_object(self, type, id):
253+
# type: (Literal['gc'], int) -> resource.GC
254+
pass
241255
@overload
242-
def create_resource_object(self, type: Literal['colormap'], id: int) -> colormap.Colormap: ...
256+
def create_resource_object(self, type, id):
257+
# type: (Literal['colormap'], int) -> resource.Colormap
258+
pass
243259
@overload
244-
def create_resource_object(self, type: Literal['cursor'], id: int) -> cursor.Cursor: ...
260+
def create_resource_object(self, type, id):
261+
# type: (Literal['cursor'], int) -> resource.Cursor
262+
pass
263+
@overload
264+
def create_resource_object(self, type, id):
265+
# type: (str, int) -> resource.Resource
266+
pass
245267
def create_resource_object(self, type, id):
246268
# type: (str, int) -> resource.Resource
247269
"""Create a resource object of type for the integer id. type

Xlib/ext/security.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from array import array
3838
_SliceableBuffer = Union[bytes, bytearray, memoryview, array[Any], mmap]
3939

40-
4140
extname = 'SECURITY'
4241

4342

Xlib/ext/shape.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from Xlib.xobject import resource, drawable
1313
from collections.abc import Sequence
1414

15-
1615
extname = 'SHAPE'
1716

1817
OP = rq.Card8

Xlib/protocol/display.py

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,18 @@ def __len__(self):
8080
return len(self.view)
8181

8282
if TYPE_CHECKING:
83-
def __contains__(self, other: object) -> bool: ...
83+
def __contains__(self, other):
84+
# type: (object) -> bool
85+
pass
8486

8587
@overload
86-
def __getitem__(self, key: int) -> int: ...
88+
def __getitem__(self, key):
89+
# type: (int) -> int
90+
pass
8791
@overload
88-
def __getitem__(self, key: slice) -> bytes: ...
89-
92+
def __getitem__(self, key):
93+
# type: (slice) -> bytes
94+
pass
9095
def __getitem__(self, key):
9196
# type: (slice | int) -> bytes | int
9297
if isinstance(key, slice):
@@ -341,31 +346,51 @@ def free_resource_id(self, rid):
341346
finally:
342347
self.resource_id_lock.release()
343348

344-
345349
if TYPE_CHECKING:
346350
@overload
347-
def get_resource_class(self, class_name: Literal['resource'], default: object = ...) -> type[resource.Resource]: ...
351+
def get_resource_class(self, class_name, default = None):
352+
# type: (Literal['resource'], object) -> type[resource.Resource]
353+
pass
348354
@overload
349-
def get_resource_class(self, class_name: Literal['drawable'], default: object = ...) -> type[drawable.Drawable]: ...
355+
def get_resource_class(self, class_name, default = None):
356+
# type: (Literal['drawable'], object) -> type[drawable.Drawable]
357+
pass
350358
@overload
351-
def get_resource_class(self, class_name: Literal['window'], default: object = ...) -> type[drawable.Window]: ...
359+
def get_resource_class(self, class_name, default = None):
360+
# type: (Literal['window'], object) -> type[drawable.Window]
361+
pass
352362
@overload
353-
def get_resource_class(self, class_name: Literal['pixmap'], default: object = ...) -> type[drawable.Pixmap]: ...
363+
def get_resource_class(self, class_name, default = None):
364+
# type: (Literal['pixmap'], object) -> type[drawable.Pixmap]
365+
pass
354366
@overload
355-
def get_resource_class(self, class_name: Literal['fontable'], default: object = ...) -> type[fontable.Fontable]: ...
367+
def get_resource_class(self, class_name, default = None):
368+
# type: (Literal['fontable'], object) -> type[fontable.Fontable]
369+
pass
356370
@overload
357-
def get_resource_class(self, class_name: Literal['font'], default: object = ...) -> type[fontable.Font]: ...
371+
def get_resource_class(self, class_name, default = None):
372+
# type: (Literal['font'], object) -> type[fontable.Font]
373+
pass
358374
@overload
359-
def get_resource_class(self, class_name: Literal['gc'], default: object = ...) -> type[fontable.GC]: ...
375+
def get_resource_class(self, class_name, default = None):
376+
# type: (Literal['gc'], object) -> type[fontable.GC]
377+
pass
360378
@overload
361-
def get_resource_class(self, class_name: Literal['colormap'], default: object = ...) -> type[colormap.Colormap]: ...
379+
def get_resource_class(self, class_name, default = None):
380+
# type: (Literal['colormap'], object) -> type[colormap.Colormap]
381+
pass
362382
@overload
363-
def get_resource_class(self, class_name: Literal['cursor'], default: object) -> type[cursor.Cursor]: ...
383+
def get_resource_class(self, class_name, default):
384+
# type: (Literal['cursor'], object) -> type[cursor.Cursor]
385+
pass
364386
@overload
365-
def get_resource_class(self, class_name: str, default: _T) -> type[_ResourceBaseClass] | _T: ...
387+
def get_resource_class(self, class_name, default):
388+
# type: (str, _T) -> type[_ResourceBaseClass] | _T
389+
pass
366390
@overload
367-
def get_resource_class(self, class_name: str, default: None = ...) -> type[_ResourceBaseClass] | None: ...
368-
391+
def get_resource_class(self, class_name, default = None):
392+
# type: (str, None) -> type[_ResourceBaseClass] | None
393+
pass
369394
def get_resource_class(self, class_name, default = None):
370395
# type: (str, _T | None) -> _T | None
371396
"""class = d.get_resource_class(class_name, default = None)

Xlib/protocol/rq.py

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,13 @@ def __init__(self, name, codes = (), default = None):
333333

334334
if TYPE_CHECKING:
335335
@overload
336-
def check_value(self, value: Callable[[], _T]) -> _T: ...
336+
def check_value(self, value):
337+
# type: (Callable[[], _T]) -> _T
338+
pass
337339
@overload
338-
def check_value(self, value: _T) -> _T: ...
340+
def check_value(self, value):
341+
# type: (_T) -> _T
342+
pass
339343
def check_value(self, value):
340344
# type: (Callable[[], _T] | _T) -> _T
341345
if hasattr(value, self.cast_function):
@@ -449,12 +453,16 @@ def pack_value(self, val):
449453
return val_bytes + b'\0' * ((4 - slen % 4) % 4), slen, None
450454
else:
451455
return val_bytes, slen, None
456+
452457
if TYPE_CHECKING:
453458
@overload
454-
def parse_binary_value(self, data: _T, display: object, length: None, format: object) -> tuple[_T, Literal[b'']]: ...
459+
def parse_binary_value(self, data, display, length, format):
460+
# type: (_T, object, None, object) -> tuple[_T, Literal[b'']]
461+
pass
455462
@overload
456-
def parse_binary_value(self, data: _SliceableBuffer, display: object, length: int, format: object) -> tuple[_SliceableBuffer, _SliceableBuffer]: ...
457-
463+
def parse_binary_value(self, data, display, length, format):
464+
# type: (_SliceableBuffer, object, int, object) -> tuple[_SliceableBuffer, _SliceableBuffer]
465+
pass
458466
def parse_binary_value(self, data, display, length, format):
459467
# type: (_SliceableBuffer, object, int, object) -> tuple[_SliceableBuffer, _SliceableBuffer]
460468
if length is None:
@@ -491,10 +499,13 @@ def pack_value(self, val):
491499

492500
if TYPE_CHECKING:
493501
@overload
494-
def parse_binary_value(self, data: bytes | bytearray, display: object, length: None, format: object) -> tuple[str, Literal[b'']]: ...
502+
def parse_binary_value(self, data, display, length, format):
503+
# type: (bytes | bytearray, object, None, object) -> tuple[str, Literal[b'']]
504+
pass
495505
@overload
496-
def parse_binary_value(self, data: _SliceableBuffer, display: object, length: int, format: object) -> tuple[str, _SliceableBuffer]: ...
497-
506+
def parse_binary_value(self, data, display, length, format):
507+
# type: (_SliceableBuffer, object, int, object) -> tuple[str, _SliceableBuffer]
508+
pass
498509
def parse_binary_value(self, data, display, length, format):
499510
# type: (bytes | bytearray, object, int, object) -> tuple[str, bytes | bytearray]
500511
if length is None:
@@ -554,7 +565,7 @@ class List(ValueField):
554565
The type of data objects must be provided as an object with the
555566
following attributes and methods:
556567
557-
...
568+
pass
558569
559570
"""
560571

@@ -1190,13 +1201,18 @@ def pack_value(self, value):
11901201
# Structs generate their attributes
11911202
# TODO: Complete all classes inheriting from Struct
11921203
# and create a type-only class for all direct instances
1193-
def __getattr__(self, __name: str) -> Any: ...
1204+
def __getattr__(self, __name):
1205+
# type: (str) -> Any
1206+
pass
11941207

11951208
@overload
1196-
def parse_value(self, val: _SliceableBuffer, display: display.Display | None, rawdict: Literal[True]) -> dict[str, Any]: ...
1209+
def parse_value(self, val, display, rawdict):
1210+
# type: (_SliceableBuffer, display.Display | None, Literal[True]) -> dict[str, Any]
1211+
pass
11971212
@overload
1198-
def parse_value(self, val: _SliceableBuffer, display: display.Display | None, rawdict: Literal[False] = ...) -> DictWrapper:...
1199-
1213+
def parse_value(self, val, display, rawdict = False):
1214+
# type: (_SliceableBuffer, display.Display | None, Literal[False]) -> DictWrapper
1215+
pass
12001216
def parse_value(self, val, display, rawdict = 0):
12011217
# type: (_SliceableBuffer, display.Display | None, bool) -> dict[str, Any] | DictWrapper
12021218

@@ -1243,9 +1259,13 @@ def parse_value(self, val, display, rawdict = 0):
12431259

12441260
if TYPE_CHECKING:
12451261
@overload
1246-
def parse_binary(self, data: _SliceableBuffer, display: display.Display | None, rawdict: Literal[True]) -> tuple[dict[str, Any], _SliceableBuffer]: ...
1262+
def parse_binary(self, data, display, rawdict):
1263+
# type: (_SliceableBuffer, display.Display | None, Literal[True]) -> tuple[dict[str, Any], _SliceableBuffer]
1264+
pass
12471265
@overload
1248-
def parse_binary(self, data: _SliceableBuffer, display: display.Display | None, rawdict: Literal[False] = ...) -> tuple[DictWrapper , _SliceableBuffer]:...
1266+
def parse_binary(self, data, display, rawdict = False):
1267+
# type: (_SliceableBuffer, display.Display | None, Literal[False]) -> tuple[DictWrapper , _SliceableBuffer]
1268+
pass
12491269
def parse_binary(self, data, display, rawdict = 0):
12501270
# type: (_SliceableBuffer, display.Display | None, bool) -> tuple[DictWrapper | dict[str, Any], _SliceableBuffer]
12511271

@@ -1417,7 +1437,9 @@ def __getattr__(self, attr):
14171437
except KeyError:
14181438
raise AttributeError(attr)
14191439
if TYPE_CHECKING:
1420-
def __setattr__(self, __name: str, __value: Any) -> None: ...
1440+
def __setattr__(self, __name, __value):
1441+
# type: (str, Any) -> None
1442+
pass
14211443

14221444
class DictWrapper(GetAttrData):
14231445
def __init__(self, dict):

Xlib/rdb.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@
3939
from collections.abc import Iterable, Sequence
4040
from _typeshed import SupportsRead, SupportsDunderLT, SupportsDunderGT
4141
class SupportsDunderEQ(Protocol):
42-
def __eq__(self, __other: object) -> bool: ...
42+
def __eq__(self, __other: object):
43+
# type: (object) -> bool
44+
pass
4345
class SupportsComparisons(
4446
SupportsDunderLT[object], SupportsDunderGT[object], SupportsDunderEQ, Protocol
45-
): ...
47+
): pass
4648
from Xlib import display
4749
_T = TypeVar("_T")
4850
_C = TypeVar("_C", bound=SupportsComparisons)
@@ -328,10 +330,13 @@ def __getitem__(self, keys_tuple):
328330

329331
if TYPE_CHECKING:
330332
@overload
331-
def get(self, res: str, cls: str, default: None = ...) -> Any: ...
333+
def get(self, res, cls, default = None):
334+
# type: (str, str, None) -> Any
335+
pass
332336
@overload
333-
def get(self, res: str, cls: str, default: _T) -> _T: ...
334-
337+
def get(self, res, cls, default):
338+
# type: (str, str, _T) -> _T
339+
pass
335340
def get(self, res, cls, default = None):
336341
# type: (str, str, object) -> Any
337342
"""get(name, class [, default])

Xlib/support/connect.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
except ImportError:
2929
TYPE_CHECKING = False
3030
if TYPE_CHECKING:
31+
if sys.platform == 'OpenVMS':
32+
from Xlib.support.vms_connect import get_display as get_display, get_socket as get_socket
33+
else:
34+
from Xlib.support.unix_connect import get_display as get_display, get_socket as get_socket
3135
import socket
3236
from Xlib.support.unix_connect import _Protocol
3337
_Address = Union[tuple[Any, ...], str]
@@ -64,12 +68,6 @@
6468
def _relative_import(modname):
6569
return importlib.import_module('..' + modname, __name__)
6670

67-
if TYPE_CHECKING:
68-
if sys.platform == 'OpenVMS':
69-
from Xlib.support.vms_connect import get_display as get_display, get_socket as get_socket
70-
else:
71-
from Xlib.support.unix_connect import get_display as get_display, get_socket as get_socket
72-
7371
def get_display(display):
7472
# type: (str | None) -> tuple[str, str | None, str | None, int, int]
7573
"""dname, protocol, host, dno, screen = get_display(display)

0 commit comments

Comments
 (0)