diff mbox series

[v3,10/16] qapi/expr.py: Remove single-letter variable

Message ID 20210223003408.964543-11-jsnow@redhat.com
State New
Headers show
Series qapi: static typing conversion, pt3 | expand

Commit Message

John Snow Feb. 23, 2021, 12:34 a.m. UTC
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Cleber Rosa <crosa@redhat.com>
---
 scripts/qapi/expr.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Markus Armbruster Feb. 25, 2021, 2:03 p.m. UTC | #1
Why?  Is it to appease a style checker?

I disagree with a blanket ban of single-letter variable names.

If @f is deemed too terrible to live, then I'd prefer @feat over
@feature, because it's more visually distant to @features.

John Snow <jsnow@redhat.com> writes:

> Signed-off-by: John Snow <jsnow@redhat.com>
> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
> Reviewed-by: Cleber Rosa <crosa@redhat.com>
> ---
>  scripts/qapi/expr.py | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
> index 3235a3b809e..473ee4f7f7e 100644
> --- a/scripts/qapi/expr.py
> +++ b/scripts/qapi/expr.py
> @@ -214,14 +214,14 @@ def check_features(features: Optional[object],
>          raise QAPISemError(info, "'features' must be an array")
>      features[:] = [f if isinstance(f, dict) else {'name': f}
>                     for f in features]
> -    for f in features:
> +    for feature in features:
>          source = "'features' member"
> -        assert isinstance(f, dict)
> -        check_keys(f, info, source, ['name'], ['if'])
> -        check_name_is_str(f['name'], info, source)
> -        source = "%s '%s'" % (source, f['name'])
> -        check_name_str(f['name'], info, source)
> -        check_if(f, info, source)
> +        assert isinstance(feature, dict)
> +        check_keys(feature, info, source, ['name'], ['if'])
> +        check_name_is_str(feature['name'], info, source)
> +        source = "%s '%s'" % (source, feature['name'])
> +        check_name_str(feature['name'], info, source)
> +        check_if(feature, info, source)
>  
>  
>  def check_enum(expr: Expression, info: QAPISourceInfo) -> None:
John Snow Feb. 25, 2021, 9:56 p.m. UTC | #2
On 2/25/21 9:03 AM, Markus Armbruster wrote:
> Why?  Is it to appease a style checker?
> 
> I disagree with a blanket ban of single-letter variable names.
> 
> If @f is deemed too terrible to live, then I'd prefer @feat over
> @feature, because it's more visually distant to @features.
> 
Yeah, pylint. We've changed some of these already and I've had reviews 
from you, Eduardo and Cleber. I thought there was some consensus, but 
maybe I misunderstood.

I generally agree that we should avoid single-letter variable names and 
would like to discourage adding new ones. Loop variables are a bit of a 
border-case. They're obviously fine in comprehensions.

There's not too many cases left. Mostly it's "for m in members" and "for 
f in features". We agreed earlier to use "memb" for members. I suppose 
'feat' matches.

--js

> John Snow <jsnow@redhat.com> writes:
> 
>> Signed-off-by: John Snow <jsnow@redhat.com>
>> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
>> Reviewed-by: Cleber Rosa <crosa@redhat.com>
>> ---
>>   scripts/qapi/expr.py | 14 +++++++-------
>>   1 file changed, 7 insertions(+), 7 deletions(-)
>>
>> diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
>> index 3235a3b809e..473ee4f7f7e 100644
>> --- a/scripts/qapi/expr.py
>> +++ b/scripts/qapi/expr.py
>> @@ -214,14 +214,14 @@ def check_features(features: Optional[object],
>>           raise QAPISemError(info, "'features' must be an array")
>>       features[:] = [f if isinstance(f, dict) else {'name': f}
>>                      for f in features]
>> -    for f in features:
>> +    for feature in features:
>>           source = "'features' member"
>> -        assert isinstance(f, dict)
>> -        check_keys(f, info, source, ['name'], ['if'])
>> -        check_name_is_str(f['name'], info, source)
>> -        source = "%s '%s'" % (source, f['name'])
>> -        check_name_str(f['name'], info, source)
>> -        check_if(f, info, source)
>> +        assert isinstance(feature, dict)
>> +        check_keys(feature, info, source, ['name'], ['if'])
>> +        check_name_is_str(feature['name'], info, source)
>> +        source = "%s '%s'" % (source, feature['name'])
>> +        check_name_str(feature['name'], info, source)
>> +        check_if(feature, info, source)
>>   
>>   
>>   def check_enum(expr: Expression, info: QAPISourceInfo) -> None:
diff mbox series

Patch

diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
index 3235a3b809e..473ee4f7f7e 100644
--- a/scripts/qapi/expr.py
+++ b/scripts/qapi/expr.py
@@ -214,14 +214,14 @@  def check_features(features: Optional[object],
         raise QAPISemError(info, "'features' must be an array")
     features[:] = [f if isinstance(f, dict) else {'name': f}
                    for f in features]
-    for f in features:
+    for feature in features:
         source = "'features' member"
-        assert isinstance(f, dict)
-        check_keys(f, info, source, ['name'], ['if'])
-        check_name_is_str(f['name'], info, source)
-        source = "%s '%s'" % (source, f['name'])
-        check_name_str(f['name'], info, source)
-        check_if(f, info, source)
+        assert isinstance(feature, dict)
+        check_keys(feature, info, source, ['name'], ['if'])
+        check_name_is_str(feature['name'], info, source)
+        source = "%s '%s'" % (source, feature['name'])
+        check_name_str(feature['name'], info, source)
+        check_if(feature, info, source)
 
 
 def check_enum(expr: Expression, info: QAPISourceInfo) -> None: