comparison mercurial/pycompat.py @ 49802:f3f33980f19b

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.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 14 Dec 2022 01:38:52 -0500
parents 9cd327509cd4
children 55d45d0de4e7
comparison
equal deleted inserted replaced
49801:9cd327509cd4 49802:f3f33980f19b
126 rawinput = input 126 rawinput = input
127 getargspec = inspect.getfullargspec 127 getargspec = inspect.getfullargspec
128 128
129 long = int 129 long = int
130 130
131 if getattr(sys, 'argv', None) is not None: 131 if builtins.getattr(sys, 'argv', None) is not None:
132 # On POSIX, the char** argv array is converted to Python str using 132 # On POSIX, the char** argv array is converted to Python str using
133 # Py_DecodeLocale(). The inverse of this is Py_EncodeLocale(), which 133 # Py_DecodeLocale(). The inverse of this is Py_EncodeLocale(), which
134 # isn't directly callable from Python code. In practice, os.fsencode() 134 # isn't directly callable from Python code. In practice, os.fsencode()
135 # can be used instead (this is recommended by Python's documentation 135 # can be used instead (this is recommended by Python's documentation
136 # for sys.argv). 136 # for sys.argv).
218 def __new__(cls, s=b''): 218 def __new__(cls, s=b''):
219 if isinstance(s, bytestr): 219 if isinstance(s, bytestr):
220 return s 220 return s
221 if not isinstance( 221 if not isinstance(
222 s, (bytes, bytearray) 222 s, (bytes, bytearray)
223 ) and not hasattr( # hasattr-py3-only 223 ) and not builtins.hasattr( # hasattr-py3-only
224 s, u'__bytes__' 224 s, u'__bytes__'
225 ): 225 ):
226 s = str(s).encode('ascii') 226 s = str(s).encode('ascii')
227 return bytes.__new__(cls, s) 227 return bytes.__new__(cls, s)
228 228
295 295
296 296
297 def getdoc(obj): 297 def getdoc(obj):
298 """Get docstring as bytes; may be None so gettext() won't confuse it 298 """Get docstring as bytes; may be None so gettext() won't confuse it
299 with _('')""" 299 with _('')"""
300 doc = getattr(obj, '__doc__', None) 300 doc = builtins.getattr(obj, '__doc__', None)
301 if doc is None: 301 if doc is None:
302 return doc 302 return doc
303 return sysbytes(doc) 303 return sysbytes(doc)
304 304
305 305