Skip to content

Commit 80eacfa

Browse files
Fight MyPy.
1 parent e348097 commit 80eacfa

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

Tools/clinic/libclinic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
# Utility functions
6969
"FormatCounterFormatter",
7070
"NULL",
71-
"Null",
71+
"NullType",
7272
"Sentinels",
7373
"VersionTuple",
7474
"compute_checksum",

Tools/clinic/libclinic/converter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ def __init__(self,
207207
if self.default_type == ():
208208
conv_name = self.__class__.__name__.removesuffix('_converter')
209209
fail(f"A '{conv_name}' parameter cannot be marked optional.")
210-
if (self.default_type is not None
211-
and default is not unknown
210+
if (default is not unknown
212211
and not isinstance(default, self.default_type)
213212
):
214213
if isinstance(self.default_type, type):

Tools/clinic/libclinic/converters.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,12 @@ class bool_converter(CConverter):
109109
def converter_init(self, *, accept: TypeSet = {object}) -> None:
110110
if accept == {int}:
111111
self.format_unit = 'i'
112-
self.default_type = int
112+
self.default_type = int # type: ignore[assignment]
113113
elif accept != {object}:
114114
fail(f"bool_converter: illegal 'accept' argument {accept!r}")
115115

116116
def c_default_init(self) -> None:
117+
assert isinstance(self.default, int)
117118
self.c_default = str(int(self.default))
118119

119120
def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> str | None:
@@ -170,6 +171,7 @@ def converter_init(self) -> None:
170171

171172
def c_default_init(self) -> None:
172173
default = self.default
174+
assert isinstance(default, bytes)
173175
if default == b"'":
174176
self.c_default = r"'\''"
175177
elif default == b'"':
@@ -313,11 +315,11 @@ def converter_init(
313315
) -> None:
314316
if accept == {str}:
315317
self.format_unit = 'C'
316-
self.default_type = str
317-
if isinstance(self.default, self.default_type):
318+
self.default_type = str # type: ignore[assignment]
319+
if isinstance(self.default, str):
318320
if len(self.default) != 1:
319321
fail(f"int_converter: illegal default value {self.default!r}")
320-
elif accept != {int}:
322+
elif accept == {int}:
321323
fail(f"int_converter: illegal 'accept' argument {accept!r}")
322324
if type is not None:
323325
self.type = type
@@ -436,7 +438,7 @@ def converter_init(self, *, accept: TypeSet = {int},
436438
self.allow_negative = allow_negative
437439
if accept == {int}:
438440
self.format_unit = 'n'
439-
self.default_type = int
441+
self.default_type = int # type: ignore[assignment]
440442
elif accept == {int, NoneType}:
441443
if self.allow_negative:
442444
self.converter = '_Py_convert_optional_to_ssize_t'
@@ -518,7 +520,7 @@ class slice_index_converter(CConverter):
518520
def converter_init(self, *, accept: TypeSet = {int, NoneType}) -> None:
519521
if accept == {int}:
520522
self.converter = '_PyEval_SliceIndexNotNone'
521-
self.default_type = int
523+
self.default_type = int # type: ignore[assignment]
522524
self.nullable = False
523525
elif accept == {int, NoneType}:
524526
self.converter = '_PyEval_SliceIndex'
@@ -983,7 +985,7 @@ def converter_init(
983985
self.accept = accept
984986
if accept == {str}:
985987
self.converter = '_PyUnicode_WideCharString_Converter'
986-
self.default_type = (str, NullType)
988+
self.default_type = (str, NullType) # type: ignore[assignment]
987989
elif accept == {str, NoneType}:
988990
self.converter = '_PyUnicode_WideCharString_Opt_Converter'
989991
else:
@@ -1050,13 +1052,13 @@ def converter_init(self, *, accept: TypeSet = {buffer}) -> None:
10501052
self.default_type = (str, bytes, NullType, NoneType)
10511053
elif accept == {str, buffer}:
10521054
self.format_unit = 's*'
1053-
self.default_type = (str, bytes, NullType)
1055+
self.default_type = (str, bytes, NullType) # type: ignore[assignment]
10541056
elif accept == {buffer}:
10551057
self.format_unit = 'y*'
1056-
self.default_type = (bytes, NullType)
1058+
self.default_type = (bytes, NullType) # type: ignore[assignment]
10571059
elif accept == {rwbuffer}:
10581060
self.format_unit = 'w*'
1059-
self.default_type = NullType
1061+
self.default_type = NullType # type: ignore[assignment]
10601062
else:
10611063
fail("Py_buffer_converter: illegal combination of arguments")
10621064

0 commit comments

Comments
 (0)