[apparmor] [patch] type_is_str(): make pyflakes3 happy

Seth Arnold seth.arnold at canonical.com
Thu Aug 11 22:13:28 UTC 2016


On Thu, Aug 11, 2016 at 11:34:38PM +0200, Christian Boltz wrote:
> Hello,
> 
> pyflakes3 doesn't check sys.version and therefore complains about 
> 'unicode' being undefined. 
> 
> This patch defines unicode as alias of str to make pyflakes3 happy, and 
> as a side effect, simplifies type_is_str(). 
> 
> 
> I propose this patch for trunk and 2.10. 

Acked-by: Seth Arnold <seth.arnold at canonical.com>

Acked for both, thanks

> 
> 
> [ 01-type_is_str-make-pyflakes3-happy.diff ] 
> 
> --- utils/apparmor/common.py    2015-12-12 13:34:40.545997223 +0100 
> +++ utils/apparmor/common.py    2016-08-11 23:28:00.228632532 +0200 
> @@ -245,11 +245,12 @@ 
>         return False 
>     return True 
>  
> +if sys.version_info[0] > 2: 
> +    unicode = str  # python 3 dropped the unicode type. To keep type_is_str() simple (and pyflakes3 happy), re-create it as alias of str. 
> + 
> def type_is_str(var): 
>     ''' returns True if the given variable is a str (or unicode string when using python 2)''' 
> -    if type(var) == str: 
> -        return True 
> -    elif sys.version_info[0] < 3 and type(var) == unicode:  # python 2 sometimes uses the 'unicode' type 
> +    if type(var) in [str, unicode]:  # python 2 sometimes uses the 'unicode' type 
>         return True 
>     else: 
>         return False 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20160811/22df0117/attachment.pgp>


More information about the AppArmor mailing list