Subject: Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes

From: Donald Hunter <[email-masked]>
Date: Tue, 18 Nov 2025 09:20:50 +0000

Jakub Kicinski <[email-masked]> writes:

> On Sun, 16 Nov 2025 21:28:43 +0200 Gal Pressman wrote:
>>
>> +    def print_attr_list(attr_names, attr_set):
>
> It nesting functions inside main() a common pattern for Python?
> Having a function declared in the middle of another function,
> does not seem optimal to me, but for some reason Claude loves
> to do that.

It's common for closure-like things and for scoping. Reviewing this
again, these add a lot of noise to main() and would be better separated
out.

To be fair, I started it with `def output(msg)` but I'd argue it is a
closure-like scoped helper thing :-)

>> +        """Print a list of attributes with their types and documentation."""
>> +        for attr_name in attr_names:
>> +            if attr_name in attr_set.attrs:
>> +                attr = attr_set.attrs[attr_name]
>> +                attr_info = f'  - {attr_name}: {attr.type}'
>> +                if 'enum' in attr.yaml:
>> +                    attr_info += f" (enum: {attr.yaml['enum']})"
>> +                if attr.yaml.get('doc'):
>> +                    doc_text = textwrap.indent(attr.yaml['doc'], '    ')
>> +                    attr_info += f"\n{doc_text}"
>> +                print(attr_info)
>> +            else:
>> +                print(f'  - {attr_name}')
>> +