Skip to content

Commit e4b45aa

Browse files
committed
Update a few type annotations.
Arguments to functions and methods in the gdb module have mostly been declared as positional-only arguments up to this point. The idea behind doing so is to lessen the likelihood of a compatibility issue in the gdbmongo package if a newer version of GDB chooses to use a different name as a keyword argument.
1 parent 7678b6d commit e4b45aa

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

gdbmongo/abseil_printers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class AbslHashMapPrinterBase(AbslPrinterProtocol):
123123
# pylint: disable=missing-function-docstring
124124
"""Pretty-printer base class for absl::node_hash_map<K, V> and absl::flat_hash_map<K, V>."""
125125

126-
def __init__(self, val: gdb.Value) -> None:
126+
def __init__(self, val: gdb.Value, /) -> None:
127127
self.key_type = val.type.template_argument(0)
128128
self.value_type = val.type.template_argument(1)
129129
self.size = int(val["size_"])

gdbmongo/stdlib_printers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
3030
class MyPrinter:
3131
32-
def __init__(self, val):
32+
def __init__(self, val: gdb.Value, /) -> None:
3333
self.val = val
3434
self.cursor = val["_cursor"]
3535
36-
def to_string(self):
36+
def to_string(self) -> str:
3737
# The class is aliased here as a local variable for some brevity.
3838
UniquePointerPrinter = gdbmongo.stdlib_printers.UniquePointerPrinter
3939
cursor = UniquePointerPrinter("std::unique_ptr", self.cursor).pointer.dereference()

gdbmongo/stdlib_xmethods.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
3030
class MyPrinter:
3131
32-
def __init__(self, val):
32+
def __init__(self, val: gdb.Value, /) -> None:
3333
self.val = val
3434
self.cursor = val["_cursor"]
3535
36-
def to_string(self):
36+
def to_string(self) -> str:
3737
xmethod_worker = stdlib_xmethods.UniquePtrMethodsMatcher().match(
3838
self.cursor.type, "operator*")
3939

stubs/gdb/printing.pyi

+5-7
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ from gdb._value import Value
3030
class _SupportsDisplayHint(typing.Protocol):
3131

3232
@abc.abstractmethod
33-
def display_hint(
34-
self
35-
) -> typing.Literal["string"] | typing.Literal["array"] | typing.Literal["map"] | None:
33+
def display_hint(self) -> typing.Literal["string", "array", "map", None]:
3634
raise NotImplementedError
3735

3836

@@ -77,7 +75,7 @@ class SubPrettyPrinter:
7775

7876
class RegexpCollectionPrettyPrinter(PrettyPrinter):
7977

80-
def __init__(self, name: str) -> None:
78+
def __init__(self, name: str, /) -> None:
8179
...
8280

8381
def add_printer(self, name: str, regexp: str,
@@ -93,7 +91,7 @@ class FlagEnumerationPrinter(PrettyPrinter):
9391

9492

9593
def register_pretty_printer(obj: Objfile | Progspace | None,
96-
printer: typing.Callable[[Value], _SupportsToString
97-
| _SupportsChildren | None],
98-
replace: bool = False) -> None:
94+
printer: typing.Callable[[Value],
95+
_SupportsToString | _SupportsChildren | None],
96+
/, *, replace: bool = False) -> None:
9997
...

0 commit comments

Comments
 (0)