diff mbox series

[v2,03/13] bitbake-setup: Set function default to None

Message ID 20260331160703.3137930-4-rob.woolley@windriver.com
State New
Headers show
Series bitbake-setup PyPI Packaging | expand

Commit Message

Rob Woolley March 31, 2026, 4:06 p.m. UTC
The function defaults are evaluated once and use across calls
can lead to unexpected behaviour.

Set the value to none and let the function initialize the value
in the case when the value is not set.

Resolves B006 from flake8-bugbear

Signed-off-by: Rob Woolley <rob.woolley@windriver.com>
---
 bin/bitbake-setup | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Richard Purdie April 1, 2026, 9:43 p.m. UTC | #1
On Tue, 2026-03-31 at 09:06 -0700, Rob Woolley via lists.openembedded.org wrote:
> The function defaults are evaluated once and use across calls
> can lead to unexpected behaviour.
> 
> Set the value to none and let the function initialize the value
> in the case when the value is not set.
> 
> Resolves B006 from flake8-bugbear
> 
> Signed-off-by: Rob Woolley <rob.woolley@windriver.com>
> ---
>  bin/bitbake-setup | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/bin/bitbake-setup b/bin/bitbake-setup
> index 313962cd4..f90f01f55 100755
> --- a/bin/bitbake-setup
> +++ b/bin/bitbake-setup
> @@ -46,7 +46,7 @@ def color_enabled() -> bool:
>  def get_diff_color_param() -> str:
>      return "--color=always" if color_enabled() else "--color=never"
>  
> -def print_configs(prompt: str, choices: list[str], descriptions: list[str] = []):
> +def print_configs(prompt: str, choices: list[str], descriptions: list[str] = None):

This breaks the typing as None is not a list. Adrian then patched it to
fix that but that caused it's own set of problems as it required python
3.10.

Whilst I agree there is a problem, I cannot take this patch in this
form, we need to find a different solution.

Cheers,

Richard
diff mbox series

Patch

diff --git a/bin/bitbake-setup b/bin/bitbake-setup
index 313962cd4..f90f01f55 100755
--- a/bin/bitbake-setup
+++ b/bin/bitbake-setup
@@ -46,7 +46,7 @@  def color_enabled() -> bool:
 def get_diff_color_param() -> str:
     return "--color=always" if color_enabled() else "--color=never"
 
-def print_configs(prompt: str, choices: list[str], descriptions: list[str] = []):
+def print_configs(prompt: str, choices: list[str], descriptions: list[str] = None):
     """
     Helper function to print a list of choices and align the output.
     Each option name is made bold to stand out, unless color is not enabled in