[PATCH 4 of 6] byteify-strings: broaden handling of attr* functions

Yuya Nishihara yuya at tcha.org
Fri Aug 2 09:15:09 EDT 2019


On Fri, 02 Aug 2019 10:22:15 +0200, Raphaël Gomès wrote:
> # HG changeset patch
> # User Raphaël Gomès <rgomes at octobus.net>
> # Date 1564733030 -7200
> #      Fri Aug 02 10:03:50 2019 +0200
> # Node ID edff9054a1a327d3d444d4acfde0879a92742549
> # Parent  2ba0327a754304b371c06d84a80ab1871e02fa66
> # EXP-Topic byteify-strings
> byteify-strings: broaden handling of attr* functions
> 
> The current safeguard that makes sure that `getattr`, etc. is not a method is
> too restrictive as it is easy to ignore wrappers use as `util.getattr`.
> 
> This change also adds other "good candidates": `wrapfunction`, `wrapclass`
> and `addattr`.
> 
> diff -r 2ba0327a7543 -r edff9054a1a3 contrib/byteify-strings.py
> --- a/contrib/byteify-strings.py	Fri Aug 02 09:55:32 2019 +0200
> +++ b/contrib/byteify-strings.py	Fri Aug 02 10:03:50 2019 +0200
> @@ -178,8 +178,10 @@
>              fn = t.string
>  
>              # *attr() builtins don't accept byte strings to 2nd argument.
> -            if (fn in ('getattr', 'setattr', 'hasattr', 'safehasattr') and
> -                    not _isop(i - 1, '.')):
> +            if fn in (
> +                'getattr', 'setattr', 'hasattr', 'safehasattr', 'wrapfunction',
> +                'wrapclass', 'addattr'
> +            ):

IIRC, Mercurial APIs such as util.safehasattr() are supposed to take bytes.


More information about the Mercurial-devel mailing list