Re: [PATCH v3 3/4] pylibfdt: Return string instead of bytearray from getprop()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Thu, May 17, 2018 at 11:09:15PM -0600, Simon Glass wrote:
> The return value is not actually mutable, so it seems more correct to
> return a string rather than a bytearray.
> 
> Suggested-by: David Gibson <david@xxxxxxxxxxxxxxxxxxxxx>
> Signed-off-by: Simon Glass <sjg@xxxxxxxxxxxx>

So.. this is a good idea.  However, I'd suggest using bytes() instead
of str().  AFAICT it will do exactly the same thing now (in Python2),
but has the bonus of also being correct for Python3.  It also makes it
a bit clearer that we're talking about a bytestring, not a Unicode
string.

> ---
> 
> Changes in v3: None
> Changes in v2: None
> 
>  pylibfdt/libfdt.i | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
> index 2c104ac..7e915cf 100644
> --- a/pylibfdt/libfdt.i
> +++ b/pylibfdt/libfdt.i
> @@ -365,7 +365,7 @@ class Fdt:
>              quiet: Errors to ignore (empty to raise on all errors)
>  
>          Returns:
> -            Value of property as a bytearray, or -ve error number
> +            Value of property as a string, or -ve error number
>  
>          Raises:
>              FdtError if any error occurs (e.g. the property is not found)
> @@ -374,7 +374,7 @@ class Fdt:
>                                 quiet)
>          if isinstance(pdata, (int)):
>              return pdata
> -        return bytearray(pdata[0])
> +        return str(pdata[0])
>  
>      def get_phandle(self, nodeoffset):
>          """Get the phandle of a node

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux