Skip to content

Commit e681235

Browse files
committed
typing: fix code review
1 parent 47373a2 commit e681235

File tree

12 files changed

+43
-42
lines changed

12 files changed

+43
-42
lines changed

mesonbuild/arglist.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def __getitem__(self, index: int) -> str: # noqa: F811
164164
def __getitem__(self, index: slice) -> T.MutableSequence[str]: # noqa: F811
165165
pass
166166

167-
def __getitem__(self, index): # type: ignore # noqa: F811
167+
def __getitem__(self, index: T.Union[int, slice]) -> T.Union[str, T.MutableSequence[str]]: # noqa: F811
168168
self.flush_pre_post()
169169
return self._container[index]
170170

@@ -176,9 +176,9 @@ def __setitem__(self, index: int, value: str) -> None: # noqa: F811
176176
def __setitem__(self, index: slice, value: T.Iterable[str]) -> None: # noqa: F811
177177
pass
178178

179-
def __setitem__(self, index, value) -> None: # type: ignore # noqa: F811
179+
def __setitem__(self, index: T.Union[int, slice], value: T.Union[str, T.Iterable[str]]) -> None: # noqa: F811
180180
self.flush_pre_post()
181-
self._container[index] = value
181+
self._container[index] = value # type: ignore # TODO: fix 'Invalid index type' and 'Incompatible types in assignment' erros
182182

183183
def __delitem__(self, index: T.Union[int, slice]) -> None:
184184
self.flush_pre_post()
@@ -314,7 +314,7 @@ def __radd__(self, args: T.Iterable[str]) -> 'CompilerArgs':
314314
new += self
315315
return new
316316

317-
def __eq__(self, other: T.Any) -> T.Union[bool]:
317+
def __eq__(self, other: object) -> T.Union[bool]:
318318
self.flush_pre_post()
319319
# Only allow equality checks against other CompilerArgs and lists instances
320320
if isinstance(other, CompilerArgs):

mesonbuild/ast/introspection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def func_build_target(self, node: BaseNode, args: T.List[TYPE_nvar], kwargs: T.D
296296
return None
297297

298298
def is_subproject(self) -> bool:
299-
return str(self.subproject) != ''
299+
return self.subproject != ''
300300

301301
def analyze(self) -> None:
302302
self.load_root_meson_file()

mesonbuild/build.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -372,22 +372,22 @@ def __init__(self, name, subdir, subproject, build_by_default, for_machine: Mach
372372
if not hasattr(self, 'typename'):
373373
raise RuntimeError('Target type is not set for target class "{}". This is a bug'.format(type(self).__name__))
374374

375-
def __lt__(self, other: T.Any) -> T.Union[bool, type(NotImplemented)]:
375+
def __lt__(self, other: object) -> T.Union[bool, type(NotImplemented)]:
376376
if not hasattr(other, 'get_id') and not callable(other.get_id):
377377
return NotImplemented
378378
return self.get_id() < other.get_id()
379379

380-
def __le__(self, other: T.Any) -> T.Union[bool, type(NotImplemented)]:
380+
def __le__(self, other: object) -> T.Union[bool, type(NotImplemented)]:
381381
if not hasattr(other, 'get_id') and not callable(other.get_id):
382382
return NotImplemented
383383
return self.get_id() <= other.get_id()
384384

385-
def __gt__(self, other: T.Any) -> T.Union[bool, type(NotImplemented)]:
385+
def __gt__(self, other: object) -> T.Union[bool, type(NotImplemented)]:
386386
if not hasattr(other, 'get_id') and not callable(other.get_id):
387387
return NotImplemented
388388
return self.get_id() > other.get_id()
389389

390-
def __ge__(self, other: T.Any) -> T.Union[bool, type(NotImplemented)]:
390+
def __ge__(self, other: object) -> T.Union[bool, type(NotImplemented)]:
391391
if not hasattr(other, 'get_id') and not callable(other.get_id):
392392
return NotImplemented
393393
return self.get_id() >= other.get_id()

mesonbuild/dependencies/boost.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __init__(self, path: Path, version_int: int):
9595
def __repr__(self) -> str:
9696
return '<BoostIncludeDir: {} -- {}>'.format(self.version, self.path)
9797

98-
def __lt__(self, other: T.Any) -> bool:
98+
def __lt__(self, other: object) -> bool:
9999
if isinstance(other, BoostIncludeDir):
100100
return (self.version_int, self.path) < (other.version_int, other.path)
101101
return NotImplemented
@@ -187,7 +187,7 @@ def __init__(self, path: Path):
187187
def __repr__(self) -> str:
188188
return '<LIB: {} {:<32} {}>'.format(self.abitag, self.mod_name, self.path)
189189

190-
def __lt__(self, other: T.Any) -> bool:
190+
def __lt__(self, other: object) -> bool:
191191
if isinstance(other, BoostLibraryFile):
192192
return (
193193
self.mod_name, self.static, self.version_lib, self.arch,
@@ -204,7 +204,7 @@ def __lt__(self, other: T.Any) -> bool:
204204
)
205205
return NotImplemented
206206

207-
def __eq__(self, other: T.Any) -> bool:
207+
def __eq__(self, other: object) -> bool:
208208
if isinstance(other, BoostLibraryFile):
209209
return self.name == other.name
210210
return NotImplemented
@@ -346,7 +346,7 @@ def __init__(self, environment: Environment, kwargs: T.Dict[str, T.Any]) -> None
346346
self.debug = buildtype.startswith('debug')
347347
self.multithreading = kwargs.get('threading', 'multi') == 'multi'
348348

349-
self.boost_root = None # type: Path
349+
self.boost_root = None # type: T.Optional[Path]
350350
self.explicit_static = 'static' in kwargs
351351

352352
# Extract and validate modules

mesonbuild/envconfig.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def get_pkg_config_libdir(self) -> T.Optional[T.List[str]]:
147147
return p
148148
return mesonlib.listify(p)
149149

150-
def __eq__(self, other: T.Any) -> 'T.Union[bool, NotImplemented]':
150+
def __eq__(self, other: object) -> 'T.Union[bool, NotImplemented]':
151151
if isinstance(other, type(self)):
152152
return self.properties == other.properties
153153
return NotImplemented
@@ -172,17 +172,17 @@ def __init__(self, system: str, cpu_family: str, cpu: str, endian: str):
172172
self.endian = endian
173173
self.is_64_bit = cpu_family in CPU_FAMILES_64_BIT # type: bool
174174

175-
def __eq__(self, other: T.Any) -> 'T.Union[bool, NotImplemented]':
176-
if self.__class__ is not other.__class__:
175+
def __eq__(self, other: object) -> 'T.Union[bool, NotImplemented]':
176+
if self.__class__ is not other.__class__ or not isinstance(other, MachineInfo):
177177
return NotImplemented
178178
return \
179179
self.system == other.system and \
180180
self.cpu_family == other.cpu_family and \
181181
self.cpu == other.cpu and \
182182
self.endian == other.endian
183183

184-
def __ne__(self, other: T.Any) -> 'T.Union[bool, NotImplemented]':
185-
if self.__class__ is not other.__class__:
184+
def __ne__(self, other: object) -> 'T.Union[bool, NotImplemented]':
185+
if self.__class__ is not other.__class__ or not isinstance(other, MachineInfo):
186186
return NotImplemented
187187
return not self.__eq__(other)
188188

mesonbuild/mesonlib.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def endswith(self, ending: str) -> bool:
289289
def split(self, s: str) -> T.List[str]:
290290
return self.fname.split(s)
291291

292-
def __eq__(self, other: T.Any) -> bool:
292+
def __eq__(self, other: object) -> bool:
293293
if not isinstance(other, File):
294294
return NotImplemented
295295
if self.hash != other.hash:
@@ -327,23 +327,23 @@ class OrderedEnum(Enum):
327327
"""
328328
An Enum which additionally offers homogeneous ordered comparison.
329329
"""
330-
def __ge__(self, other: T.Any) -> bool:
331-
if self.__class__ is other.__class__ and isinstance(self.value, int) and isinstance(other.value, int):
330+
def __ge__(self, other: object) -> bool:
331+
if self.__class__ is other.__class__ and isinstance(other, OrderedEnum)and isinstance(self.value, int) and isinstance(other.value, int):
332332
return self.value >= other.value
333333
return NotImplemented
334334

335-
def __gt__(self, other: T.Any) -> bool:
336-
if self.__class__ is other.__class__ and isinstance(self.value, int) and isinstance(other.value, int):
335+
def __gt__(self, other: object) -> bool:
336+
if self.__class__ is other.__class__ and isinstance(other, OrderedEnum)and isinstance(self.value, int) and isinstance(other.value, int):
337337
return self.value > other.value
338338
return NotImplemented
339339

340-
def __le__(self, other: T.Any) -> bool:
341-
if self.__class__ is other.__class__ and isinstance(self.value, int) and isinstance(other.value, int):
340+
def __le__(self, other: object) -> bool:
341+
if self.__class__ is other.__class__ and isinstance(other, OrderedEnum)and isinstance(self.value, int) and isinstance(other.value, int):
342342
return self.value <= other.value
343343
return NotImplemented
344344

345-
def __lt__(self, other: T.Any) -> bool:
346-
if self.__class__ is other.__class__ and isinstance(self.value, int) and isinstance(other.value, int):
345+
def __lt__(self, other: object) -> bool:
346+
if self.__class__ is other.__class__ and isinstance(other, OrderedEnum) and isinstance(self.value, int) and isinstance(other.value, int):
347347
return self.value < other.value
348348
return NotImplemented
349349

@@ -609,32 +609,32 @@ def __str__(self) -> str:
609609
def __repr__(self) -> str:
610610
return '<Version: {}>'.format(self._s)
611611

612-
def __lt__(self, other: T.Any) -> bool:
612+
def __lt__(self, other: object) -> bool:
613613
if isinstance(other, Version):
614614
return self.__cmp(other, operator.lt)
615615
return NotImplemented
616616

617-
def __gt__(self, other: T.Any) -> bool:
617+
def __gt__(self, other: object) -> bool:
618618
if isinstance(other, Version):
619619
return self.__cmp(other, operator.gt)
620620
return NotImplemented
621621

622-
def __le__(self, other: T.Any) -> bool:
622+
def __le__(self, other: object) -> bool:
623623
if isinstance(other, Version):
624624
return self.__cmp(other, operator.le)
625625
return NotImplemented
626626

627-
def __ge__(self, other: T.Any) -> bool:
627+
def __ge__(self, other: object) -> bool:
628628
if isinstance(other, Version):
629629
return self.__cmp(other, operator.ge)
630630
return NotImplemented
631631

632-
def __eq__(self, other: T.Any) -> bool:
632+
def __eq__(self, other: object) -> bool:
633633
if isinstance(other, Version):
634634
return self._v == other._v
635635
return NotImplemented
636636

637-
def __ne__(self, other: T.Any) -> bool:
637+
def __ne__(self, other: object) -> bool:
638638
if isinstance(other, Version):
639639
return self._v != other._v
640640
return NotImplemented
@@ -1115,7 +1115,7 @@ def unholder(item: T.List[_T]) -> T.List[_T]: ...
11151115
@T.overload
11161116
def unholder(item: T.List[T.Union[_T, 'ObjectHolder[_T]']]) -> T.List[_T]: ...
11171117

1118-
def unholder(item): # type: ignore # TODO for some reason mypy throws the "Function is missing a type annotation" error
1118+
def unholder(item): # type: ignore # TODO fix overload (somehow)
11191119
"""Get the held item of an object holder or list of object holders."""
11201120
if isinstance(item, list):
11211121
return [i.held_object if hasattr(i, 'held_object') else i for i in item]

mesonbuild/mintro.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
from .interpreter import Interpreter
3131
from pathlib import PurePath
3232
import typing as T
33-
import os, argparse
33+
import os
34+
import argparse
3435

3536
def get_meson_info_file(info_dir: str) -> str:
3637
return os.path.join(info_dir, 'meson-info.json')

mesonbuild/mparser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(self, tid: str, filename: str, line_start: int, lineno: int, colno:
9797
self.bytespan = bytespan # type: T.Tuple[int, int]
9898
self.value = value # type: TV_TokenTypes
9999

100-
def __eq__(self, other: T.Any) -> bool:
100+
def __eq__(self, other: object) -> bool:
101101
if isinstance(other, str):
102102
return self.tid == other
103103
elif isinstance(other, Token):

mesonbuild/scripts/depfixer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def fix_rpathtype_entry(self, rpath_dirs_to_remove: T.List[bytes], new_rpath: by
328328
new_rpath = b':'.join(new_rpaths)
329329

330330
if len(old_rpath) < len(new_rpath):
331-
msg = "New rpath must not be longer than the old one.\n Old: {!r}\n New: {!r}".format(old_rpath, new_rpath)
331+
msg = "New rpath must not be longer than the old one.\n Old: {}\n New: {}".format(old_rpath.decode('utf-8'), new_rpath.decode('utf-8'))
332332
sys.exit(msg)
333333
# The linker does read-only string deduplication. If there is a
334334
# string that shares a suffix with the rpath, they might get

mesonbuild/wrap/wrap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class WrapNotFoundException(WrapException):
107107
class PackageDefinition:
108108
def __init__(self, fname: str):
109109
self.filename = fname
110-
self.type = None # type: str
110+
self.type = None # type: T.Optional[str]
111111
self.values = {} # type: T.Dict[str, str]
112112
self.provided_deps = {} # type: T.Dict[str, T.Optional[str]]
113113
self.provided_programs = [] # type: T.List[str]

run_project_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def display_name(self) -> str:
216216
return '{} ({})'.format(self.path.as_posix(), self.name)
217217
return self.path.as_posix()
218218

219-
def __lt__(self, other: T.Any) -> bool:
219+
def __lt__(self, other: object) -> bool:
220220
if isinstance(other, TestDef):
221221
# None is not sortable, so replace it with an empty string
222222
s_id = int(self.path.name.split(' ')[0])

tools/boost_names.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ def __init__(self, name: str, shared: T.List[str], static: T.List[str], single:
4848
self.single = sorted(set(single))
4949
self.multi = sorted(set(multi))
5050

51-
def __lt__(self, other: T.Any) -> T.Union[bool, 'NotImplemented']:
51+
def __lt__(self, other: object) -> T.Union[bool, 'NotImplemented']:
5252
if isinstance(other, BoostLibrary):
5353
return self.name < other.name
5454
return NotImplemented
5555

56-
def __eq__(self, other: T.Any) -> T.Union[bool, 'NotImplemented']:
56+
def __eq__(self, other: object) -> T.Union[bool, 'NotImplemented']:
5757
if isinstance(other, BoostLibrary):
5858
return self.name == other.name
5959
elif isinstance(other, str):
@@ -71,7 +71,7 @@ def __init__(self, name: str, key: str, desc: str, libs: T.List[BoostLibrary]):
7171
self.desc = desc
7272
self.libs = libs
7373

74-
def __lt__(self, other: T.Any) -> T.Union[bool, 'NotImplemented']:
74+
def __lt__(self, other: object) -> T.Union[bool, 'NotImplemented']:
7575
if isinstance(other, BoostModule):
7676
return self.key < other.key
7777
return NotImplemented

0 commit comments

Comments
 (0)