[RFC PATCH v1 1/8] utils: codegen: ipc: Use `any()` instead of `len([]) > 0`

Jacopo Mondi jacopo.mondi at ideasonboard.com
Tue May 20 13:19:05 CEST 2025


Hi Barnabás

On Thu, May 15, 2025 at 02:00:05PM +0200, Barnabás Pőcze wrote:
> Use `any()` with a generator expression instead of constructing
> a list and checking its length.
>
> Signed-off-by: Barnabás Pőcze <barnabas.pocze at ideasonboard.com>

Reviewed-by: Jacopo Mondi <jacopo.mondi at ideasonboard.com>

> ---
>  .../ipc/generators/mojom_libcamera_generator.py    | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/utils/codegen/ipc/generators/mojom_libcamera_generator.py b/utils/codegen/ipc/generators/mojom_libcamera_generator.py
> index d9c620a05..eff29a5b8 100644
> --- a/utils/codegen/ipc/generators/mojom_libcamera_generator.py
> +++ b/utils/codegen/ipc/generators/mojom_libcamera_generator.py
> @@ -166,7 +166,7 @@ def MethodParamOutputs(method):
>      return method.response_parameters[1:]
>
>  def MethodParamsHaveFd(parameters):
> -    return len([x for x in parameters if HasFd(x)]) > 0
> +    return any(x for x in parameters if HasFd(x))
>
>  def MethodInputHasFd(method):
>      return MethodParamsHaveFd(method.parameters)
> @@ -465,9 +465,9 @@ class Generator(generator.Generator):
>              'cmd_event_enum_name': '_%sEventCmd' % self.module_name,
>              'consts': self.module.constants,
>              'enums': self.module.enums,
> -            'has_array': len([x for x in self.module.kinds.keys() if x[0] == 'a']) > 0,
> -            'has_map': len([x for x in self.module.kinds.keys() if x[0] == 'm']) > 0,
> -            'has_string': len([x for x in self.module.kinds.keys() if x[0] == 's']) > 0,
> +            'has_array': any(x for x in self.module.kinds.keys() if x[0] == 'a'),
> +            'has_map': any(x for x in self.module.kinds.keys() if x[0] == 'm'),
> +            'has_string': any(x for x in self.module.kinds.keys() if x[0] == 's'),
>              'has_namespace': self.module.mojom_namespace != '',
>              'interface_event': GetEventInterface(self.module.interfaces),
>              'interface_main': GetMainInterface(self.module.interfaces),
> @@ -485,9 +485,9 @@ class Generator(generator.Generator):
>          return {
>              'consts': self.module.constants,
>              'enums_gen_header': [x for x in self.module.enums if x.attributes is None or 'skipHeader' not in x.attributes],
> -            'has_array': len([x for x in self.module.kinds.keys() if x[0] == 'a']) > 0,
> -            'has_map': len([x for x in self.module.kinds.keys() if x[0] == 'm']) > 0,
> -            'has_string': len([x for x in self.module.kinds.keys() if x[0] == 's']) > 0,
> +            'has_array': any(x for x in self.module.kinds.keys() if x[0] == 'a'),
> +            'has_map': any(x for x in self.module.kinds.keys() if x[0] == 'm'),
> +            'has_string': any(x for x in self.module.kinds.keys() if x[0] == 's'),
>              'structs_gen_header': [x for x in self.module.structs if x.attributes is None or 'skipHeader' not in x.attributes],
>              'structs_gen_serializer': [x for x in self.module.structs if x.attributes is None or 'skipSerdes' not in x.attributes],
>          }
> --
> 2.49.0
>


More information about the libcamera-devel mailing list