Re: [PATCH v5 06/13] scripts: generate_rust_analyzer.py: add type hints

Tamir Duberstein
2025-03-31T17:47:48Z

On Mon, Mar 31, 2025 at 1:09 PM Daniel Almeida
<daniel.almeida@collabora.com> wrote:
>
> Hi Tamir,
>
> [snip]
>
> > rust_project = {
> > - "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs),
> > + "crates": generate_crates(
> > + args.srctree,
> > + args.objtree,
> > + args.sysroot_src,
> > + args.exttree,
> > + defaultdict(
> > + list,
> > + {
> > + crate: vals.lstrip("--cfg").split()
> > + for crate, vals in map(lambda cfg: cfg.split("=", 1), args.cfgs)
> > + },
> > + ),
> > + ),
> > "sysroot": str(args.sysroot),
> > }
> >
> >
> > --
> > 2.49.0
> >
>
> I found `args_crates_cfgs()` a lot easier to understand, but I guess this is a
> matter of taste. I also find that this `defaultdict()` call slightly pollutes
> the surrounding code, but again, that might be just me.

Would extracting a local variable suffice?

> Regardless, running `mypy` still passes, and there is no change to the output.
>
> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>

Thanks!