diff --git a/mesonbuild/cmake/client.py b/mesonbuild/cmake/client.py index 4375eb9ee..4581d6d5d 100644 --- a/mesonbuild/cmake/client.py +++ b/mesonbuild/cmake/client.py @@ -48,8 +48,8 @@ CMAKE_REPLY_TYPES = { # Base CMake server message classes class MessageBase: - def __init__(self, type: str, cookie: str): - self.type = type + def __init__(self, msg_type: str, cookie: str): + self.type = msg_type self.cookie = cookie def to_dict(self) -> dict: @@ -61,8 +61,8 @@ class MessageBase: class RequestBase(MessageBase): cookie_counter = 0 - def __init__(self, type: str): - super().__init__(type, self.gen_cookie()) + def __init__(self, msg_type: str): + super().__init__(msg_type, self.gen_cookie()) @staticmethod def gen_cookie(): @@ -404,13 +404,13 @@ class CMakeClient: raw_data = self.readMessageRaw() if 'type' not in raw_data: raise CMakeException('The "type" attribute is missing from the message') - type = raw_data['type'] - func = self.type_map.get(type, None) + msg_type = raw_data['type'] + func = self.type_map.get(msg_type, None) if not func: - raise CMakeException('Recieved unknown message type "{}"'.format(type)) - for i in CMAKE_MESSAGE_TYPES[type]: + raise CMakeException('Recieved unknown message type "{}"'.format(msg_type)) + for i in CMAKE_MESSAGE_TYPES[msg_type]: if i not in raw_data: - raise CMakeException('Key "{}" is missing from CMake server message type {}'.format(i, type)) + raise CMakeException('Key "{}" is missing from CMake server message type {}'.format(i, msg_type)) return func(raw_data) def writeMessage(self, msg: MessageBase) -> None: diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py index 488c99c9e..7782555fb 100644 --- a/mesonbuild/cmake/interpreter.py +++ b/mesonbuild/cmake/interpreter.py @@ -414,7 +414,7 @@ class CMakeInterpreter: def string(value: str) -> StringNode: return StringNode(token(val=value)) - def id(value: str) -> IdNode: + def id_node(value: str) -> IdNode: return IdNode(token(val=value)) def nodeify(value): @@ -433,7 +433,11 @@ class CMakeInterpreter: args.arguments += [nodeify(x) for x in elements] return ArrayNode(args, 0, 0, 0, 0) - def function(name: str, args=[], kwargs={}) -> FunctionNode: + def function(name: str, args=None, kwargs=None) -> FunctionNode: + if args is None: + args = [] + if kwargs is None: + kwargs = {} args_n = ArgumentNode(token()) if not isinstance(args, list): args = [args] @@ -442,7 +446,11 @@ class CMakeInterpreter: func_n = FunctionNode(self.subdir, 0, 0, 0, 0, name, args_n) return func_n - def method(obj: BaseNode, name: str, args=[], kwargs={}) -> MethodNode: + def method(obj: BaseNode, name: str, args=None, kwargs=None) -> MethodNode: + if args is None: + args = [] + if kwargs is None: + kwargs = {} args_n = ArgumentNode(token()) if not isinstance(args, list): args = [args] @@ -466,7 +474,7 @@ class CMakeInterpreter: assert(isinstance(i, ConverterTarget)) if i.name not in processed: process_target(i) - link_with += [id(processed[i.name]['tgt'])] + link_with += [id_node(processed[i.name]['tgt'])] for i in tgt.object_libs: assert(isinstance(i, ConverterTarget)) if i.name not in processed: @@ -490,11 +498,11 @@ class CMakeInterpreter: tgt_kwargs = { 'link_args': tgt.link_flags + tgt.link_libraries, 'link_with': link_with, - 'include_directories': id(inc_var), + 'include_directories': id_node(inc_var), 'install': tgt.install, 'install_dir': tgt.install_dir, 'override_options': tgt.override_options, - 'objects': [method(id(x), 'extract_all_objects') for x in objec_libs], + 'objects': [method(id_node(x), 'extract_all_objects') for x in objec_libs], } # Handle compiler args @@ -510,14 +518,14 @@ class CMakeInterpreter: # declare_dependency kwargs dep_kwargs = { 'link_args': tgt.link_flags + tgt.link_libraries, - 'link_with': id(tgt_var), - 'include_directories': id(inc_var), + 'link_with': id_node(tgt_var), + 'include_directories': id_node(inc_var), } # Generate the function nodes inc_node = assign(inc_var, function('include_directories', tgt.includes)) src_node = assign(src_var, function('files', tgt.sources + tgt.generated)) - tgt_node = assign(tgt_var, function(tgt_func, [base_name, id(src_var)], tgt_kwargs)) + tgt_node = assign(tgt_var, function(tgt_func, [base_name, id_node(src_var)], tgt_kwargs)) dep_node = assign(dep_var, function('declare_dependency', kwargs=dep_kwargs)) # Add the nodes to the ast