[PATCH 08/26] rv/rvgen: simplify boolean comparison

Wander Lairson Costa posted 26 patches 2 weeks, 5 days ago
There is a newer version of this series
[PATCH 08/26] rv/rvgen: simplify boolean comparison
Posted by Wander Lairson Costa 2 weeks, 5 days ago
Replace explicit boolean comparison with truthiness test in the dot2c
module. The previous implementation used the redundant pattern of
comparing a boolean variable directly to False, which is not idiomatic
Python and adds unnecessary verbosity to the code.

Python's truthiness allows for more concise and readable boolean
checks. The expression "if not first" is clearer and more Pythonic
than "if first == False" while maintaining identical semantics. This
pattern is preferred in PEP 8 and is the standard approach in the
Python community.

This change continues the ongoing code quality improvements to align
the codebase with modern Python best practices.

Signed-off-by: Wander Lairson Costa <wander@redhat.com>
---
 tools/verification/rvgen/rvgen/dot2c.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/verification/rvgen/rvgen/dot2c.py b/tools/verification/rvgen/rvgen/dot2c.py
index c97bb9466af6d..fa9e9ae16640f 100644
--- a/tools/verification/rvgen/rvgen/dot2c.py
+++ b/tools/verification/rvgen/rvgen/dot2c.py
@@ -202,7 +202,7 @@ class Dot2c(Automata):
         line = ""
         first = True
         for state in self.states:
-            if first == False:
+            if not first:
                 line = line + ', '
             else:
                 first = False
-- 
2.52.0
Re: [PATCH 08/26] rv/rvgen: simplify boolean comparison
Posted by Nam Cao 2 weeks, 2 days ago
Wander Lairson Costa <wander@redhat.com> writes:
> Replace explicit boolean comparison with truthiness test in the dot2c
> module. The previous implementation used the redundant pattern of
> comparing a boolean variable directly to False, which is not idiomatic
> Python and adds unnecessary verbosity to the code.
>
> Python's truthiness allows for more concise and readable boolean
> checks. The expression "if not first" is clearer and more Pythonic
> than "if first == False" while maintaining identical semantics. This
> pattern is preferred in PEP 8 and is the standard approach in the
> Python community.
>
> This change continues the ongoing code quality improvements to align
> the codebase with modern Python best practices.
>
> Signed-off-by: Wander Lairson Costa <wander@redhat.com>

Reviewed-by: Nam Cao <namcao@linutronix.de>
Re: [PATCH 08/26] rv/rvgen: simplify boolean comparison
Posted by Gabriele Monaco 2 weeks, 5 days ago
On Mon, 2026-01-19 at 17:45 -0300, Wander Lairson Costa wrote:
> Replace explicit boolean comparison with truthiness test in the dot2c
> module. The previous implementation used the redundant pattern of
> comparing a boolean variable directly to False, which is not idiomatic
> Python and adds unnecessary verbosity to the code.
> 
> Python's truthiness allows for more concise and readable boolean
> checks. The expression "if not first" is clearer and more Pythonic
> than "if first == False" while maintaining identical semantics. This
> pattern is preferred in PEP 8 and is the standard approach in the
> Python community.
> 
> This change continues the ongoing code quality improvements to align
> the codebase with modern Python best practices.
> 
> Signed-off-by: Wander Lairson Costa <wander@redhat.com>

I'm starting to wonder if those simple cleanup patches with a tiny change and 3
paragraph of commit message aren't a bit too noisy. We may put at least the
simple ones together.

Other than that:

Reviewed-by: Gabriele Monaco <gmonaco@redhat.com>

Thanks,
Gabriele

> ---
>  tools/verification/rvgen/rvgen/dot2c.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/verification/rvgen/rvgen/dot2c.py
> b/tools/verification/rvgen/rvgen/dot2c.py
> index c97bb9466af6d..fa9e9ae16640f 100644
> --- a/tools/verification/rvgen/rvgen/dot2c.py
> +++ b/tools/verification/rvgen/rvgen/dot2c.py
> @@ -202,7 +202,7 @@ class Dot2c(Automata):
>          line = ""
>          first = True
>          for state in self.states:
> -            if first == False:
> +            if not first:
>                  line = line + ', '
>              else:
>                  first = False