changeset 50810:8250ecb53f30

byteify-strings: passe sysstr to attr function and wrapper These function now accepts string so we should not do byteify them anymore.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 10 Jul 2023 15:59:04 +0200
parents d64df6b35007
children caa0a25f7243
files contrib/byteify-strings.py tests/test-byteify-strings.t
diffstat 2 files changed, 15 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- 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