Re: [Fuego] [PATCH 1/8] Create mylong function as a compatible replacement for long()

"Bird, Tim" <[email protected]> Fri, 13 May 2022 17:05:02 +0000
Newsgroups dev.linux.lists.fuego
Message-ID <BYAPR13MB2503FC220852713E8418AD91FDCA9@BYAPR13MB2503.namprd13.prod.outlook.com>
This fix was interesting... :-)

> -----Original Message-----
> From: [email protected] <[email protected]=
m>
>=20
> From: Shivanand Kunijadar <[email protected]>
>=20
> Python3 removed the long() variable type and cast.
> Define mylong() in try and except block which replaces mylong()
> with long() in python2 and returns same passed value in python3.
>=20
> Signed-off-by: Shivanand Kunijadar <[email protected]>
> ---
>  scripts/deorphan-runs.py | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>=20
> diff --git a/scripts/deorphan-runs.py b/scripts/deorphan-runs.py
> index c81ed24..82dcacb 100755
> --- a/scripts/deorphan-runs.py
> +++ b/scripts/deorphan-runs.py
> @@ -77,6 +77,14 @@ class data_class:
>          else:
>              return item
>=20
> +# define mylong to work in python2 and 3
> +try:
> +    val =3D long(4)
> +    mylong =3D long
> +except:
> +    def mylong(x):
> +        return x

Interesting use of exception to define mylong function in Python3!

Since long() in python2 can also convert strings, it would be better,
in the general case, if the last line here was:
return int(x)
to get equivalent functionality.

However, since this is only used one place, with well-defined, numeric
inputs, this is fine as written.

> +
>  def populate_build_data():
>      # construct the build_data map to hold information about this build
>      build_data =3D data_class()
> @@ -88,7 +96,7 @@ def populate_build_data():
>      test_name =3D os.path.basename(test_name)
>      build_data.job_name =3D "%s.%s.%s" % (board_name, test.spec, test_na=
me)
>      build_data.workspace =3D conf.FUEGO_RW+"/buildzone"
> -    build_data.start_time =3D long(time.time() * 1000)
> +    build_data.start_time =3D mylong(time.time() * 1000)
>      build_data.reboot_flag =3D test.reboot
>      build_data.rebuild_flag =3D test.rebuild
>      build_data.precleanup_flag =3D test.precleanup
> --
> 2.20.1
>=20

Applied.

Just a question - the top of deorphan-runs.py has this invocation line:
#!/usr/bin/python

Are you running this on a system where /usr/bin/python is python3 and not p=
ython2?
I'm just curious.  If so, what Linux distro is that that?

Thanks!
 -- Tim