diff mbox series

knotty: Cast two variables to int in integer expressions

Message ID 20251105071405.636900-1-zboszor@gmail.com
State New
Headers show
Series knotty: Cast two variables to int in integer expressions | expand

Commit Message

Zoltán Böszörményi Nov. 5, 2025, 7:14 a.m. UTC
Python 3.14 complain about these:

Traceback (most recent call last):
  File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 722, in main
    termfilter.updateFooter()
    ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 339, in updateFooter
    lines = self.getlines(content)
  File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 370, in getlines
    lines = lines + 1 + int(len(line) / (self.columns + 1))
                                         ~~~~~~~~~~~~~^~~
TypeError: can only concatenate str (not "int") to str

and

Traceback (most recent call last):
  File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 722, in main
    termfilter.updateFooter()
    ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 341, in updateFooter
    for tasknum, task in enumerate(tasks[:(self.rows - 1 - lines)]):
                                           ~~~~~~~~~~^~~
TypeError: unsupported operand type(s) for -: 'str' and 'int'

Cast self.rows and self.columns to int.

Signed-off-by: Zoltán Böszörményi <zboszor@gmail.com>
---
 lib/bb/ui/knotty.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Peter Kjellerstedt Nov. 5, 2025, 10:27 a.m. UTC | #1
> -----Original Message-----
> From: bitbake-devel@lists.openembedded.org <bitbake-devel@lists.openembedded.org> On Behalf Of Zoltan Boszormenyi via lists.openembedded.org
> Sent: den 5 november 2025 08:14
> To: bitbake-devel@lists.openembedded.org
> Cc: Zoltán Böszörményi <zboszor@gmail.com>
> Subject: [bitbake-devel] [PATCH] knotty: Cast two variables to int in integer expressions
> 
> Python 3.14 complain about these:
> 
> Traceback (most recent call last):
>   File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 722, in main
>     termfilter.updateFooter()
>     ~~~~~~~~~~~~~~~~~~~~~~~^^
>   File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 339, in updateFooter
>     lines = self.getlines(content)
>   File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 370, in getlines
>     lines = lines + 1 + int(len(line) / (self.columns + 1))
>                                          ~~~~~~~~~~~~~^~~
> TypeError: can only concatenate str (not "int") to str
> 
> and
> 
> Traceback (most recent call last):
>   File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 722, in main
>     termfilter.updateFooter()
>     ~~~~~~~~~~~~~~~~~~~~~~~^^
>   File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 341, in updateFooter
>     for tasknum, task in enumerate(tasks[:(self.rows - 1 - lines)]):
>                                            ~~~~~~~~~~^~~
> TypeError: unsupported operand type(s) for -: 'str' and 'int'
> 
> Cast self.rows and self.columns to int.
> 
> Signed-off-by: Zoltán Böszörményi <zboszor@gmail.com>
> ---
>  lib/bb/ui/knotty.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py
> index 00258c80f..f04607df8 100644
> --- a/lib/bb/ui/knotty.py
> +++ b/lib/bb/ui/knotty.py
> @@ -338,7 +338,7 @@ class TerminalFilter(object):
>              print('', file=self._footer_buf)
>          lines = self.getlines(content)
>          if not self.quiet:
> -            for tasknum, task in enumerate(tasks[:(self.rows - 1 - lines)]):
> +            for tasknum, task in enumerate(tasks[:(int(self.rows) - 1 - lines)]):
>                  if isinstance(task, tuple):
>                      pbar, msg, progress, rate, start_time = task
>                      if not pbar.start_time:
> @@ -367,7 +367,7 @@ class TerminalFilter(object):
>      def getlines(self, content):
>          lines = 0
>          for line in content.split("\n"):
> -            lines = lines + 1 + int(len(line) / (self.columns + 1))
> +            lines = lines + 1 + int(len(line) / (int(self.columns) + 1))
>          return lines
> 
>      def finish(self):
> --
> 2.51.1

Wouldn't it make more sense to make getTerminalColumns() return two integers?
If I understand the code correctly, this should only be a problem when 
reading the sizes from the environment, so changing this:

                cr = (os.environ['LINES'], os.environ['COLUMNS'])

to this:

                cr = (int(os.environ['LINES']), int(os.environ['COLUMNS']))

should solve the problem.

//Peter
Peter Kjellerstedt Nov. 5, 2025, 10:32 a.m. UTC | #2
> -----Original Message-----
> From: bitbake-devel@lists.openembedded.org <bitbake-devel@lists.openembedded.org> On Behalf Of Peter Kjellerstedt via lists.openembedded.org
> Sent: den 5 november 2025 11:27
> To: zboszor@gmail.com; bitbake-devel@lists.openembedded.org
> Subject: Re: [bitbake-devel] [PATCH] knotty: Cast two variables to int in integer expressions
> 
> > -----Original Message-----
> > From: bitbake-devel@lists.openembedded.org <bitbake-devel@lists.openembedded.org> On Behalf Of Zoltan Boszormenyi via lists.openembedded.org
> > Sent: den 5 november 2025 08:14
> > To: bitbake-devel@lists.openembedded.org
> > Cc: Zoltán Böszörményi <zboszor@gmail.com>
> > Subject: [bitbake-devel] [PATCH] knotty: Cast two variables to int in integer expressions
> >
> > Python 3.14 complain about these:
> >
> > Traceback (most recent call last):
> >   File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 722, in main
> >     termfilter.updateFooter()
> >     ~~~~~~~~~~~~~~~~~~~~~~~^^
> >   File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 339, in updateFooter
> >     lines = self.getlines(content)
> >   File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 370, in getlines
> >     lines = lines + 1 + int(len(line) / (self.columns + 1))
> >                                          ~~~~~~~~~~~~~^~~
> > TypeError: can only concatenate str (not "int") to str
> >
> > and
> >
> > Traceback (most recent call last):
> >   File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 722, in main
> >     termfilter.updateFooter()
> >     ~~~~~~~~~~~~~~~~~~~~~~~^^
> >   File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 341, in updateFooter
> >     for tasknum, task in enumerate(tasks[:(self.rows - 1 - lines)]):
> >                                            ~~~~~~~~~~^~~
> > TypeError: unsupported operand type(s) for -: 'str' and 'int'
> >
> > Cast self.rows and self.columns to int.
> >
> > Signed-off-by: Zoltán Böszörményi <zboszor@gmail.com>
> > ---
> >  lib/bb/ui/knotty.py | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py
> > index 00258c80f..f04607df8 100644
> > --- a/lib/bb/ui/knotty.py
> > +++ b/lib/bb/ui/knotty.py
> > @@ -338,7 +338,7 @@ class TerminalFilter(object):
> >              print('', file=self._footer_buf)
> >          lines = self.getlines(content)
> >          if not self.quiet:
> > -            for tasknum, task in enumerate(tasks[:(self.rows - 1 - lines)]):
> > +            for tasknum, task in enumerate(tasks[:(int(self.rows) - 1 - lines)]):
> >                  if isinstance(task, tuple):
> >                      pbar, msg, progress, rate, start_time = task
> >                      if not pbar.start_time:
> > @@ -367,7 +367,7 @@ class TerminalFilter(object):
> >      def getlines(self, content):
> >          lines = 0
> >          for line in content.split("\n"):
> > -            lines = lines + 1 + int(len(line) / (self.columns + 1))
> > +            lines = lines + 1 + int(len(line) / (int(self.columns) + 1))
> >          return lines
> >
> >      def finish(self):
> > --
> > 2.51.1
> 
> Wouldn't it make more sense to make getTerminalColumns() return two integers?
> If I understand the code correctly, this should only be a problem when
> reading the sizes from the environment, so changing this:
> 
>                 cr = (os.environ['LINES'], os.environ['COLUMNS'])
> 
> to this:
> 
>                 cr = (int(os.environ['LINES']), int(os.environ['COLUMNS']))
> 
> should solve the problem.
> 
> //Peter

Oh, and I would also change the subject to say:

knotty: Make sure getTerminalColumns() returns two integers

//Peter
Zoltán Böszörményi Nov. 5, 2025, 10:46 a.m. UTC | #3
2025. 11. 05. 11:32 keltezéssel, Peter Kjellerstedt írta:
>> -----Original Message-----
>> From: bitbake-devel@lists.openembedded.org <bitbake-devel@lists.openembedded.org> On Behalf Of Peter Kjellerstedt via lists.openembedded.org
>> Sent: den 5 november 2025 11:27
>> To: zboszor@gmail.com; bitbake-devel@lists.openembedded.org
>> Subject: Re: [bitbake-devel] [PATCH] knotty: Cast two variables to int in integer expressions
>>
>>> -----Original Message-----
>>> From: bitbake-devel@lists.openembedded.org <bitbake-devel@lists.openembedded.org> On Behalf Of Zoltan Boszormenyi via lists.openembedded.org
>>> Sent: den 5 november 2025 08:14
>>> To: bitbake-devel@lists.openembedded.org
>>> Cc: Zoltán Böszörményi <zboszor@gmail.com>
>>> Subject: [bitbake-devel] [PATCH] knotty: Cast two variables to int in integer expressions
>>>
>>> Python 3.14 complain about these:
>>>
>>> Traceback (most recent call last):
>>>    File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 722, in main
>>>      termfilter.updateFooter()
>>>      ~~~~~~~~~~~~~~~~~~~~~~~^^
>>>    File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 339, in updateFooter
>>>      lines = self.getlines(content)
>>>    File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 370, in getlines
>>>      lines = lines + 1 + int(len(line) / (self.columns + 1))
>>>                                           ~~~~~~~~~~~~~^~~
>>> TypeError: can only concatenate str (not "int") to str
>>>
>>> and
>>>
>>> Traceback (most recent call last):
>>>    File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 722, in main
>>>      termfilter.updateFooter()
>>>      ~~~~~~~~~~~~~~~~~~~~~~~^^
>>>    File "/mnt2/zozo/yocto-5.3/bitbake/lib/bb/ui/knotty.py", line 341, in updateFooter
>>>      for tasknum, task in enumerate(tasks[:(self.rows - 1 - lines)]):
>>>                                             ~~~~~~~~~~^~~
>>> TypeError: unsupported operand type(s) for -: 'str' and 'int'
>>>
>>> Cast self.rows and self.columns to int.
>>>
>>> Signed-off-by: Zoltán Böszörményi <zboszor@gmail.com>
>>> ---
>>>   lib/bb/ui/knotty.py | 4 ++--
>>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py
>>> index 00258c80f..f04607df8 100644
>>> --- a/lib/bb/ui/knotty.py
>>> +++ b/lib/bb/ui/knotty.py
>>> @@ -338,7 +338,7 @@ class TerminalFilter(object):
>>>               print('', file=self._footer_buf)
>>>           lines = self.getlines(content)
>>>           if not self.quiet:
>>> -            for tasknum, task in enumerate(tasks[:(self.rows - 1 - lines)]):
>>> +            for tasknum, task in enumerate(tasks[:(int(self.rows) - 1 - lines)]):
>>>                   if isinstance(task, tuple):
>>>                       pbar, msg, progress, rate, start_time = task
>>>                       if not pbar.start_time:
>>> @@ -367,7 +367,7 @@ class TerminalFilter(object):
>>>       def getlines(self, content):
>>>           lines = 0
>>>           for line in content.split("\n"):
>>> -            lines = lines + 1 + int(len(line) / (self.columns + 1))
>>> +            lines = lines + 1 + int(len(line) / (int(self.columns) + 1))
>>>           return lines
>>>
>>>       def finish(self):
>>> --
>>> 2.51.1
>> Wouldn't it make more sense to make getTerminalColumns() return two integers?
>> If I understand the code correctly, this should only be a problem when
>> reading the sizes from the environment, so changing this:
>>
>>                  cr = (os.environ['LINES'], os.environ['COLUMNS'])
>>
>> to this:
>>
>>                  cr = (int(os.environ['LINES']), int(os.environ['COLUMNS']))
>>
>> should solve the problem.
>>
>> //Peter
> Oh, and I would also change the subject to say:
>
> knotty: Make sure getTerminalColumns() returns two integers
>
> //Peter

Thanks for the suggestions, I will send a new patch.

FWIW, this change allows using Fedora 43 with Python 3.14.0 as the build host.
diff mbox series

Patch

diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py
index 00258c80f..f04607df8 100644
--- a/lib/bb/ui/knotty.py
+++ b/lib/bb/ui/knotty.py
@@ -338,7 +338,7 @@  class TerminalFilter(object):
             print('', file=self._footer_buf)
         lines = self.getlines(content)
         if not self.quiet:
-            for tasknum, task in enumerate(tasks[:(self.rows - 1 - lines)]):
+            for tasknum, task in enumerate(tasks[:(int(self.rows) - 1 - lines)]):
                 if isinstance(task, tuple):
                     pbar, msg, progress, rate, start_time = task
                     if not pbar.start_time:
@@ -367,7 +367,7 @@  class TerminalFilter(object):
     def getlines(self, content):
         lines = 0
         for line in content.split("\n"):
-            lines = lines + 1 + int(len(line) / (self.columns + 1))
+            lines = lines + 1 + int(len(line) / (int(self.columns) + 1))
         return lines
 
     def finish(self):