pycompat: deprecate using bytes
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 08 Dec 2022 15:57:42 +0100
changeset 50924 9bffc6c4e4c5
parent 50923 c642c03969ff
child 50925 13eab1a5db78
pycompat: deprecate using bytes Python2 has been dropped for a while, so lets comply to the signature of the global function. This open the way to drop the use of `pycompat.getattr` and company, and, especially, the associated `util.safehasattr`.
mercurial/pycompat.py
--- a/mercurial/pycompat.py	Thu Aug 31 02:41:33 2023 +0200
+++ b/mercurial/pycompat.py	Thu Dec 08 15:57:42 2022 +0100
@@ -355,6 +355,13 @@
 def _wrapattrfunc(f):
     @functools.wraps(f)
     def w(object, name, *args):
+        if isinstance(name, bytes):
+            from . import util
+
+            msg = b'function "%s" take `str` as argument, not `bytes`'
+            fname = f.__name__.encode('ascii')
+            msg %= fname
+            util.nouideprecwarn(msg, b"6.6", stacklevel=2)
         return f(object, sysstr(name), *args)
 
     return w