py3: drop redundant `u''` prefixes on string literals
Strings are unicode on Python 3. These were rewritten by `pyupgrade`.
It's arguably better to fix the `contrib` stuff upstream and then re-vendor it,
but I don't feel like waiting for that, and then all of the regression testing
involved to get a minor improvement in the codebase. It was last vendored 5
years ago, and will likely be a large change anyway to drop py2 support. Also,
we've already made minor formatting changes to it locally.
--- a/contrib/python-zstandard/tests/test_compressor.py Mon Jan 06 14:07:43 2025 -0500
+++ b/contrib/python-zstandard/tests/test_compressor.py Mon Jan 06 14:15:40 2025 -0500
@@ -1678,7 +1678,7 @@
with self.assertRaisesRegex(
TypeError, "item 0 not a bytes like object"
):
- cctx.multi_compress_to_buffer([u"foo"])
+ cctx.multi_compress_to_buffer(["foo"])
def test_empty_input(self):
cctx = zstd.ZstdCompressor()
--- a/contrib/python-zstandard/tests/test_data_structures.py Mon Jan 06 14:07:43 2025 -0500
+++ b/contrib/python-zstandard/tests/test_data_structures.py Mon Jan 06 14:15:40 2025 -0500
@@ -164,15 +164,15 @@
# Python 3 doesn't appear to convert unicode to Py_buffer.
if sys.version_info[0] >= 3:
with self.assertRaises(TypeError):
- zstd.get_frame_parameters(u"foobarbaz")
+ zstd.get_frame_parameters("foobarbaz")
else:
# CPython will convert unicode to Py_buffer. But CFFI won't.
if zstd.backend == "cffi":
with self.assertRaises(TypeError):
- zstd.get_frame_parameters(u"foobarbaz")
+ zstd.get_frame_parameters("foobarbaz")
else:
with self.assertRaises(zstd.ZstdError):
- zstd.get_frame_parameters(u"foobarbaz")
+ zstd.get_frame_parameters("foobarbaz")
def test_invalid_input_sizes(self):
with self.assertRaisesRegex(
--- a/contrib/python-zstandard/tests/test_decompressor.py Mon Jan 06 14:07:43 2025 -0500
+++ b/contrib/python-zstandard/tests/test_decompressor.py Mon Jan 06 14:15:40 2025 -0500
@@ -1370,7 +1370,7 @@
dctx.decompress_content_dict_chain([])
with self.assertRaisesRegex(ValueError, "chunk 0 must be bytes"):
- dctx.decompress_content_dict_chain([u"foo"])
+ dctx.decompress_content_dict_chain(["foo"])
with self.assertRaisesRegex(ValueError, "chunk 0 must be bytes"):
dctx.decompress_content_dict_chain([True])
@@ -1408,7 +1408,7 @@
dctx = zstd.ZstdDecompressor()
with self.assertRaisesRegex(ValueError, "chunk 1 must be bytes"):
- dctx.decompress_content_dict_chain([initial, u"foo"])
+ dctx.decompress_content_dict_chain([initial, "foo"])
with self.assertRaisesRegex(ValueError, "chunk 1 must be bytes"):
dctx.decompress_content_dict_chain([initial, None])
@@ -1485,7 +1485,7 @@
with self.assertRaisesRegex(
TypeError, "item 0 not a bytes like object"
):
- dctx.multi_decompress_to_buffer([u"foo"])
+ dctx.multi_decompress_to_buffer(["foo"])
with self.assertRaisesRegex(
ValueError, "could not determine decompressed size of item 0"
--- a/contrib/python-zstandard/tests/test_train_dictionary.py Mon Jan 06 14:07:43 2025 -0500
+++ b/contrib/python-zstandard/tests/test_train_dictionary.py Mon Jan 06 14:15:40 2025 -0500
@@ -25,10 +25,10 @@
def test_bad_args(self):
with self.assertRaises(TypeError):
- zstd.train_dictionary(8192, u"foo")
+ zstd.train_dictionary(8192, "foo")
with self.assertRaises(ValueError):
- zstd.train_dictionary(8192, [u"foo"])
+ zstd.train_dictionary(8192, ["foo"])
def test_no_params(self):
d = zstd.train_dictionary(8192, random_input_data())
--- a/doc/hgmanpage.py Mon Jan 06 14:07:43 2025 -0500
+++ b/doc/hgmanpage.py Mon Jan 06 14:15:40 2025 -0500
@@ -283,18 +283,18 @@
return ''.join(self.head + self.body + self.foot)
def deunicode(self, text):
- text = text.replace(u'\xa0', '\\ ')
- text = text.replace(u'\u2020', '\\(dg')
+ text = text.replace('\xa0', '\\ ')
+ text = text.replace('\u2020', '\\(dg')
return text
def visit_Text(self, node):
text = node.astext()
text = text.replace('\\', '\\e')
replace_pairs = [
- (u'-', u'\\-'),
- (u"'", u'\\(aq'),
- (u'´', u"\\'"),
- (u'`', u'\\(ga'),
+ ('-', '\\-'),
+ ("'", '\\(aq'),
+ ('´', "\\'"),
+ ('`', '\\(ga'),
]
for in_char, out_markup in replace_pairs:
text = text.replace(in_char, out_markup)
--- a/hgext/convert/bzr.py Mon Jan 06 14:07:43 2025 -0500
+++ b/hgext/convert/bzr.py Mon Jan 06 14:15:40 2025 -0500
@@ -263,7 +263,7 @@
paths = change.path
kind = change.kind
executable = change.executable
- if paths[0] == u'' or paths[1] == u'':
+ if paths[0] == '' or paths[1] == '':
# ignore changes to tree root
continue
--- a/hgext/convert/subversion.py Mon Jan 06 14:07:43 2025 -0500
+++ b/hgext/convert/subversion.py Mon Jan 06 14:15:40 2025 -0500
@@ -398,7 +398,7 @@
# Percent-decoded bytes get decoded using UTF-8 and the 'replace'
# error handler.
unicodepath = urlreq.url2pathname(unicodepath)
- if u'\N{REPLACEMENT CHARACTER}' in unicodepath:
+ if '\N{REPLACEMENT CHARACTER}' in unicodepath:
ui.warn(
_(
b'Subversion does not support non-UTF-8 '
--- a/hgext/phabricator.py Mon Jan 06 14:07:43 2025 -0500
+++ b/hgext/phabricator.py Mon Jan 06 14:15:40 2025 -0500
@@ -490,7 +490,7 @@
lambda x: encoding.unifromlocal(x) if isinstance(x, bytes) else x,
callconduit(ui, name, params),
)
- s = json.dumps(result, sort_keys=True, indent=2, separators=(u',', u': '))
+ s = json.dumps(result, sort_keys=True, indent=2, separators=(',', ': '))
ui.write(b'%s\n' % encoding.unitolocal(s))
--- a/mercurial/encoding.py Mon Jan 06 14:07:43 2025 -0500
+++ b/mercurial/encoding.py Mon Jan 06 14:15:40 2025 -0500
@@ -504,7 +504,7 @@
chars = chars[:i]
if leftside:
chars.reverse()
- u = u''.join(chars).encode(_sysstr(encoding))
+ u = ''.join(chars).encode(_sysstr(encoding))
if leftside:
return ellipsis + u
return u + ellipsis
--- a/mercurial/hgweb/wsgiheaders.py Mon Jan 06 14:07:43 2025 -0500
+++ b/mercurial/hgweb/wsgiheaders.py Mon Jan 06 14:15:40 2025 -0500
@@ -48,8 +48,8 @@
if type(value) is bytes:
return value
raise AssertionError(
- u"Header names/values must be"
- u" of type bytes (got %s)" % repr(value)
+ "Header names/values must be"
+ " of type bytes (got %s)" % repr(value)
)
def __len__(self):
--- a/mercurial/i18n.py Mon Jan 06 14:07:43 2025 -0500
+++ b/mercurial/i18n.py Mon Jan 06 14:15:40 2025 -0500
@@ -86,14 +86,14 @@
if message not in cache:
if type(message) is str:
# goofy unicode docstrings in test
- paragraphs: List[str] = message.split(u'\n\n')
+ paragraphs: List[str] = message.split('\n\n')
else:
# should be ascii, but we have unicode docstrings in test, which
# are converted to utf-8 bytes on Python 3.
paragraphs = [p.decode("utf-8") for p in message.split(b'\n\n')]
# Be careful not to translate the empty string -- it holds the
# meta data of the .po file.
- u = u'\n\n'.join([p and _ugettext(p) or u'' for p in paragraphs])
+ u = '\n\n'.join([p and _ugettext(p) or '' for p in paragraphs])
try:
# encoding.tolocal cannot be used since it will first try to
# decode the Unicode string. Calling u.decode(enc) really
--- a/mercurial/mail.py Mon Jan 06 14:07:43 2025 -0500
+++ b/mercurial/mail.py Mon Jan 06 14:15:40 2025 -0500
@@ -528,4 +528,4 @@
except UnicodeDecodeError:
pass
uparts.append(part.decode('ISO-8859-1'))
- return encoding.unitolocal(u' '.join(uparts))
+ return encoding.unitolocal(' '.join(uparts))
--- a/mercurial/pycompat.py Mon Jan 06 14:07:43 2025 -0500
+++ b/mercurial/pycompat.py Mon Jan 06 14:15:40 2025 -0500
@@ -261,7 +261,7 @@
return s
if not isinstance(s, (bytes, bytearray)) and (
isinstance(s, type)
- or not builtins.hasattr(s, u'__bytes__') # hasattr-py3-only
+ or not builtins.hasattr(s, '__bytes__') # hasattr-py3-only
):
s = str(s).encode('ascii')
return bytes.__new__(cls, s)
--- a/mercurial/store.py Mon Jan 06 14:07:43 2025 -0500
+++ b/mercurial/store.py Mon Jan 06 14:15:40 2025 -0500
@@ -125,7 +125,7 @@
these characters will be escaped by encodefunctions
"""
- winreserved = [ord(x) for x in u'\\:*?"<>|']
+ winreserved = [ord(x) for x in '\\:*?"<>|']
for x in range(32):
yield x
for x in range(126, 256):
--- a/mercurial/windows.py Mon Jan 06 14:07:43 2025 -0500
+++ b/mercurial/windows.py Mon Jan 06 14:15:40 2025 -0500
@@ -208,19 +208,19 @@
This shouldn't be called directly- use ``ui.getpass()`` instead, which
checks if the session is interactive first.
"""
- pw = u""
+ pw = ""
while True:
c = msvcrt.getwch() # pytype: disable=module-attr
- if c == u'\r' or c == u'\n':
+ if c == '\r' or c == '\n':
break
- if c == u'\003':
+ if c == '\003':
raise KeyboardInterrupt
- if c == u'\b':
+ if c == '\b':
pw = pw[:-1]
else:
pw = pw + c
- msvcrt.putwch(u'\r') # pytype: disable=module-attr
- msvcrt.putwch(u'\n') # pytype: disable=module-attr
+ msvcrt.putwch('\r') # pytype: disable=module-attr
+ msvcrt.putwch('\n') # pytype: disable=module-attr
return encoding.unitolocal(pw)
--- a/tests/test-encoding-func.py Mon Jan 06 14:07:43 2025 -0500
+++ b/tests/test-encoding-func.py Mon Jan 06 14:15:40 2025 -0500
@@ -47,21 +47,21 @@
def testlossylatin(self):
encoding.encoding = b'ascii'
- s = u'\xc0'.encode('utf-8')
+ s = '\xc0'.encode('utf-8')
l = encoding.tolocal(s)
self.assertEqual(l, b'?') # lossy
self.assertEqual(s, encoding.toutf8b(l)) # utf8 sequence preserved
def testlosslesslatin(self):
encoding.encoding = b'latin-1'
- s = u'\xc0'.encode('utf-8')
+ s = '\xc0'.encode('utf-8')
l = encoding.tolocal(s)
self.assertEqual(l, b'\xc0') # lossless
self.assertEqual(s, encoding.toutf8b(l)) # convert back to utf-8
def testlossy0xed(self):
encoding.encoding = b'euc-kr' # U+Dxxx Hangul
- s = u'\ud1bc\xc0'.encode('utf-8')
+ s = '\ud1bc\xc0'.encode('utf-8')
l = encoding.tolocal(s)
self.assertIn(b'\xed', l)
self.assertTrue(l.endswith(b'?')) # lossy
@@ -69,7 +69,7 @@
def testlossless0xed(self):
encoding.encoding = b'euc-kr' # U+Dxxx Hangul
- s = u'\ud1bc'.encode('utf-8')
+ s = '\ud1bc'.encode('utf-8')
l = encoding.tolocal(s)
self.assertEqual(l, b'\xc5\xed') # lossless
self.assertEqual(s, encoding.toutf8b(l)) # convert back to utf-8
--- a/tests/test-url.py Mon Jan 06 14:07:43 2025 -0500
+++ b/tests/test-url.py Mon Jan 06 14:15:40 2025 -0500
@@ -69,7 +69,7 @@
# Unicode (IDN) certname isn't supported
check(
- _verifycert(cert(u'\u4f8b.jp'), 'example.jp'),
+ _verifycert(cert('\u4f8b.jp'), 'example.jp'),
b'IDN in certificate not supported',
)
@@ -137,7 +137,7 @@
check(_verifycert(cert('a.*.com'), 'a.com'), b'certificate is for a.*.com')
# wildcard doesn't match IDNA prefix 'xn--'
-idna = u'püthon.python.org'.encode('idna').decode('ascii')
+idna = 'püthon.python.org'.encode('idna').decode('ascii')
check(_verifycert(cert(idna), idna), None)
check(
_verifycert(cert('x*.python.org'), idna),
@@ -150,27 +150,27 @@
# wildcard in first fragment and IDNA A-labels in sequent fragments
# are supported.
-idna = u'www*.pythön.org'.encode('idna').decode('ascii')
+idna = 'www*.pythön.org'.encode('idna').decode('ascii')
check(
- _verifycert(cert(idna), u'www.pythön.org'.encode('idna').decode('ascii')),
+ _verifycert(cert(idna), 'www.pythön.org'.encode('idna').decode('ascii')),
None,
)
check(
- _verifycert(cert(idna), u'www1.pythön.org'.encode('idna').decode('ascii')),
+ _verifycert(cert(idna), 'www1.pythön.org'.encode('idna').decode('ascii')),
None,
)
check(
- _verifycert(cert(idna), u'ftp.pythön.org'.encode('idna').decode('ascii')),
+ _verifycert(cert(idna), 'ftp.pythön.org'.encode('idna').decode('ascii')),
b'certificate is for www*.xn--pythn-mua.org',
)
check(
- _verifycert(cert(idna), u'pythön.org'.encode('idna').decode('ascii')),
+ _verifycert(cert(idna), 'pythön.org'.encode('idna').decode('ascii')),
b'certificate is for www*.xn--pythn-mua.org',
)
c = {
'notAfter': 'Jun 26 21:41:46 2011 GMT',
- 'subject': (((u'commonName', u'linuxfrz.org'),),),
+ 'subject': ((('commonName', 'linuxfrz.org'),),),
'subjectAltName': (
('DNS', 'linuxfr.org'),
('DNS', 'linuxfr.com'),
@@ -194,11 +194,11 @@
c = {
'notAfter': 'Dec 18 23:59:59 2011 GMT',
'subject': (
- ((u'countryName', u'US'),),
- ((u'stateOrProvinceName', u'California'),),
- ((u'localityName', u'Mountain View'),),
- ((u'organizationName', u'Google Inc'),),
- ((u'commonName', u'mail.google.com'),),
+ (('countryName', 'US'),),
+ (('stateOrProvinceName', 'California'),),
+ (('localityName', 'Mountain View'),),
+ (('organizationName', 'Google Inc'),),
+ (('commonName', 'mail.google.com'),),
),
}
check(_verifycert(c, 'mail.google.com'), None)
@@ -211,10 +211,10 @@
c = {
'notAfter': 'Dec 18 23:59:59 2011 GMT',
'subject': (
- ((u'countryName', u'US'),),
- ((u'stateOrProvinceName', u'California'),),
- ((u'localityName', u'Mountain View'),),
- ((u'organizationName', u'Google Inc'),),
+ (('countryName', 'US'),),
+ (('stateOrProvinceName', 'California'),),
+ (('localityName', 'Mountain View'),),
+ (('organizationName', 'Google Inc'),),
),
}
check(
@@ -226,10 +226,10 @@
c = {
'notAfter': 'Dec 18 23:59:59 2099 GMT',
'subject': (
- ((u'countryName', u'US'),),
- ((u'stateOrProvinceName', u'California'),),
- ((u'localityName', u'Mountain View'),),
- ((u'commonName', u'mail.google.com'),),
+ (('countryName', 'US'),),
+ (('stateOrProvinceName', 'California'),),
+ (('localityName', 'Mountain View'),),
+ (('commonName', 'mail.google.com'),),
),
'subjectAltName': (('othername', 'blabla'),),
}
@@ -239,10 +239,10 @@
c = {
'notAfter': 'Dec 18 23:59:59 2099 GMT',
'subject': (
- ((u'countryName', u'US'),),
- ((u'stateOrProvinceName', u'California'),),
- ((u'localityName', u'Mountain View'),),
- ((u'organizationName', u'Google Inc'),),
+ (('countryName', 'US'),),
+ (('stateOrProvinceName', 'California'),),
+ (('localityName', 'Mountain View'),),
+ (('organizationName', 'Google Inc'),),
),
'subjectAltName': (('othername', 'blabla'),),
}
@@ -258,15 +258,15 @@
# avoid denials of service by refusing more than one
# wildcard per fragment.
check(
- _verifycert({'subject': (((u'commonName', u'a*b.com'),),)}, 'axxb.com'),
+ _verifycert({'subject': ((('commonName', 'a*b.com'),),)}, 'axxb.com'),
None,
)
check(
- _verifycert({'subject': (((u'commonName', u'a*b.co*'),),)}, 'axxb.com'),
+ _verifycert({'subject': ((('commonName', 'a*b.co*'),),)}, 'axxb.com'),
b'certificate is for a*b.co*',
)
check(
- _verifycert({'subject': (((u'commonName', u'a*b*.com'),),)}, 'axxbxxc.com'),
+ _verifycert({'subject': ((('commonName', 'a*b*.com'),),)}, 'axxbxxc.com'),
b'too many wildcards in certificate DNS name: a*b*.com',
)