Mercurial > hg
changeset 42683:bbb002b378f3
byteify-strings: add cli argument to handle `attr*()` when they are methods
Certain code bases have useful utils that wrap the builtin functions, and are
called like `util.setattr`.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Fri, 02 Aug 2019 16:17:02 +0200 |
parents | 5e296f618920 |
children | 863e9e7f8850 |
files | contrib/byteify-strings.py |
diffstat | 1 files changed, 8 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/byteify-strings.py Fri Aug 02 16:14:00 2019 +0200 +++ b/contrib/byteify-strings.py Fri Aug 02 16:17:02 2019 +0200 @@ -208,8 +208,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' + ) and (opts['allow-attr-methods'] or not _isop(i - 1, '.')): arg1idx = _findargnofcall(1) if arg1idx is not None: _ensuresysstr(arg1idx) @@ -276,6 +278,9 @@ help='edit files in place') ap.add_argument('--dictiter', action='store_true', default=False, help='rewrite iteritems() and itervalues()'), + ap.add_argument('--allow-attr-methods', action='store_true', + default=False, + help='also handle attr*() when they are methods'), ap.add_argument('--treat-as-kwargs', nargs="+", default=[], help="ignore kwargs-like objects"), ap.add_argument('files', metavar='FILE', nargs='+', help='source file') @@ -283,6 +288,7 @@ opts = { 'dictiter': args.dictiter, 'treat-as-kwargs': set(args.treat_as_kwargs), + 'allow-attr-methods': args.allow_attr_methods, } for fname in args.files: if args.inplace: