RE: [bitbake-devel][PATCH V2 3/5] fetch2/crate.py: add filter_regex parameter to latest_versionstring

"Chen, Qi" <[email protected]>
Newsgroups org.openembedded.lists.bitbake-devel
Message-ID <CO6PR11MB5602D7FE3E775800610A6FA2ED3D2@CO6PR11MB5602.namprd11.prod.outlook.com>
Thanks for the suggestion. I'll use list comprehension to make codes cleaner.

Regards,
Qi

-----Original Message-----
From: Alexander Kanavin <[email protected]> 
Sent: Thursday, May 7, 2026 6:52 PM
To: Chen, Qi <[email protected]>
Cc: [email protected]; MacLeod, Randy <[email protected]>
Subject: Re: [bitbake-devel][PATCH V2 3/5] fetch2/crate.py: add filter_regex parameter to latest_versionstring

On Thu, 7 May 2026 at 08:19, <[email protected]> wrote:
>          versions = [(0, i["num"], "") for i in json_data["versions"]]
> +        if filter_regex
> +            filtered_versions = []
> +            for v in versions:
> +                if re.match(filter_regex, v[1]):
> +                    filtered_versions.append(v)
> +            versions = filtered_versions

This could also use list comprehension:

if filter_regex:
    versions = [v for v in versions if re.match(filter_regex, v[1])]

You can even form the list with a single statement by setting the condition like this:

... if not filter_regex or re.match...

but doing list comprehension twice is perhaps more clear.

Alex
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.