pycompat: explicitly prefix builtin attr usage with `builtins.`
authorMatt Harbison <matt_harbison@yahoo.com>
Wed, 14 Dec 2022 01:38:52 -0500
changeset 49802 f3f33980f19b
parent 49801 9cd327509cd4
child 49803 55d45d0de4e7
pycompat: explicitly prefix builtin attr usage with `builtins.` It doesn't seem like this would fix any bug, because the wrapped functions that take bytes instead of str are defined after these calls. But PyCharm was flagging the second and third uses, saying "Type 'str' doesn't have expected attribute 'decode'". It wasn't flagging the first, but I changed it for consistency.
mercurial/pycompat.py
--- a/mercurial/pycompat.py	Wed Dec 14 01:32:03 2022 -0500
+++ b/mercurial/pycompat.py	Wed Dec 14 01:38:52 2022 -0500
@@ -128,7 +128,7 @@
 
 long = int
 
-if getattr(sys, 'argv', None) is not None:
+if builtins.getattr(sys, 'argv', None) is not None:
     # On POSIX, the char** argv array is converted to Python str using
     # Py_DecodeLocale(). The inverse of this is Py_EncodeLocale(), which
     # isn't directly callable from Python code. In practice, os.fsencode()
@@ -220,7 +220,7 @@
             return s
         if not isinstance(
             s, (bytes, bytearray)
-        ) and not hasattr(  # hasattr-py3-only
+        ) and not builtins.hasattr(  # hasattr-py3-only
             s, u'__bytes__'
         ):
             s = str(s).encode('ascii')
@@ -297,7 +297,7 @@
 def getdoc(obj):
     """Get docstring as bytes; may be None so gettext() won't confuse it
     with _('')"""
-    doc = getattr(obj, '__doc__', None)
+    doc = builtins.getattr(obj, '__doc__', None)
     if doc is None:
         return doc
     return sysbytes(doc)