byteify-strings: passe sysstr to attr function and wrapper
These function now accepts string so we should not do byteify them anymore.
--- a/contrib/byteify-strings.py Wed Jul 12 10:59:19 2023 +0200
+++ b/contrib/byteify-strings.py Mon Jul 10 15:59:04 2023 +0200
@@ -212,18 +212,14 @@
fn = t.string
# *attr() builtins don't accept byte strings to 2nd argument.
- if (
- fn
- in (
- 'getattr',
- 'setattr',
- 'hasattr',
- 'safehasattr',
- 'wrapfunction',
- 'wrapclass',
- 'addattr',
- )
- and (opts['allow-attr-methods'] or not _isop(i - 1, '.'))
+ if fn in (
+ 'getattr',
+ 'setattr',
+ 'hasattr',
+ 'safehasattr',
+ 'wrapfunction',
+ 'wrapclass',
+ 'addattr',
):
arg1idx = _findargnofcall(1)
if arg1idx is not None:
@@ -312,12 +308,6 @@
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=[],
@@ -328,7 +318,6 @@
opts = {
'dictiter': args.dictiter,
'treat-as-kwargs': set(args.treat_as_kwargs),
- 'allow-attr-methods': args.allow_attr_methods,
}
for fname in args.files:
fname = os.path.realpath(fname)
--- a/tests/test-byteify-strings.t Wed Jul 12 10:59:19 2023 +0200
+++ b/tests/test-byteify-strings.t Mon Jul 10 15:59:04 2023 +0200
@@ -110,19 +110,6 @@
> def f():
> pass
> EOF
- $ byteify_strings testfile.py --allow-attr-methods
- setattr(o, 'a', 1)
- util.setattr(o, 'ae', 1)
- util.getattr(o, 'alksjdf', b'default')
- util.addattr(o, 'asdf')
- util.hasattr(o, 'lksjdf', b'default')
- util.safehasattr(o, 'lksjdf', b'default')
- @eh.wrapfunction(func, 'lksjdf')
- def f():
- pass
- @eh.wrapclass(klass, 'lksjdf')
- def f():
- pass
Test without attr*() as methods
@@ -142,15 +129,15 @@
> EOF
$ byteify_strings testfile.py
setattr(o, 'a', 1)
- util.setattr(o, b'ae', 1)
- util.getattr(o, b'alksjdf', b'default')
- util.addattr(o, b'asdf')
- util.hasattr(o, b'lksjdf', b'default')
- util.safehasattr(o, b'lksjdf', b'default')
- @eh.wrapfunction(func, b'lksjdf')
+ util.setattr(o, 'ae', 1)
+ util.getattr(o, 'alksjdf', b'default')
+ util.addattr(o, 'asdf')
+ util.hasattr(o, 'lksjdf', b'default')
+ util.safehasattr(o, 'lksjdf', b'default')
+ @eh.wrapfunction(func, 'lksjdf')
def f():
pass
- @eh.wrapclass(klass, b'lksjdf')
+ @eh.wrapclass(klass, 'lksjdf')
def f():
pass