summaryrefslogtreecommitdiff
path: root/babel
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2023-01-18 20:59:35 +0200
committerAarni Koskela <akx@iki.fi>2023-01-18 21:20:51 +0200
commit5f7580d40523ce8aa67f51a3eb941dc81faa47f2 (patch)
treefd92fba1f801935c8e21bbfa601c98e74890fa75 /babel
parent65d9ae36ecb9d4a4691ffb9f21f3ff11e6ff5739 (diff)
downloadbabel-5f7580d40523ce8aa67f51a3eb941dc81faa47f2.tar.gz
Apply ruff UP025 (unicode literal prefix) fix
Diffstat (limited to 'babel')
-rw-r--r--babel/dates.py14
-rw-r--r--babel/messages/catalog.py14
-rw-r--r--babel/messages/frontend.py2
-rw-r--r--babel/messages/jslexer.py2
-rw-r--r--babel/messages/pofile.py12
-rw-r--r--babel/numbers.py32
6 files changed, 38 insertions, 38 deletions
diff --git a/babel/dates.py b/babel/dates.py
index 7bfea71..26766a6 100644
--- a/babel/dates.py
+++ b/babel/dates.py
@@ -49,7 +49,7 @@ if TYPE_CHECKING:
# empty set characters ( U+2205 )."
# - https://www.unicode.org/reports/tr35/tr35-dates.html#Metazone_Names
-NO_INHERITANCE_MARKER = u'\u2205\u2205\u2205'
+NO_INHERITANCE_MARKER = '\u2205\u2205\u2205'
if pytz:
@@ -558,11 +558,11 @@ def get_timezone_gmt(
if return_z and hours == 0 and seconds == 0:
return 'Z'
elif seconds == 0 and width == 'iso8601_short':
- return u'%+03d' % hours
+ return '%+03d' % hours
elif width == 'short' or width == 'iso8601_short':
- pattern = u'%+03d%02d'
+ pattern = '%+03d%02d'
elif width == 'iso8601':
- pattern = u'%+03d:%02d'
+ pattern = '%+03d:%02d'
else:
pattern = locale.zone_formats['gmt'] % '%+03d:%02d'
return pattern % (hours, seconds // 60)
@@ -1083,10 +1083,10 @@ def format_timedelta(
break
# This really should not happen
if pattern is None:
- return u''
+ return ''
return pattern.replace('{0}', str(value))
- return u''
+ return ''
def _format_fallback_interval(
@@ -1849,7 +1849,7 @@ def parse_pattern(pattern: str) -> DateTimePattern:
else:
raise NotImplementedError(f"Unknown token type: {tok_type}")
- _pattern_cache[pattern] = pat = DateTimePattern(pattern, u''.join(result))
+ _pattern_cache[pattern] = pat = DateTimePattern(pattern, ''.join(result))
return pat
diff --git a/babel/messages/catalog.py b/babel/messages/catalog.py
index dbca10f..85f16b2 100644
--- a/babel/messages/catalog.py
+++ b/babel/messages/catalog.py
@@ -80,7 +80,7 @@ class Message:
def __init__(
self,
id: _MessageID,
- string: _MessageID | None = u'',
+ string: _MessageID | None = '',
locations: Iterable[tuple[str, int]] = (),
flags: Iterable[str] = (),
auto_comments: Iterable[str] = (),
@@ -107,7 +107,7 @@ class Message:
"""
self.id = id
if not string and self.pluralizable:
- string = (u'', u'')
+ string = ('', '')
self.string = string
self.locations = list(distinct(locations))
self.flags = set(flags)
@@ -233,7 +233,7 @@ class TranslationError(Exception):
translations are encountered."""
-DEFAULT_HEADER = u"""\
+DEFAULT_HEADER = """\
# Translations template for PROJECT.
# Copyright (C) YEAR ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
@@ -444,7 +444,7 @@ class Catalog:
value = self._force_text(value, encoding=self.charset)
if name == 'project-id-version':
parts = value.split(' ')
- self.project = u' '.join(parts[:-1])
+ self.project = ' '.join(parts[:-1])
self.version = parts[-1]
elif name == 'report-msgid-bugs-to':
self.msgid_bugs_address = value
@@ -591,7 +591,7 @@ class Catalog:
flags = set()
if self.fuzzy:
flags |= {'fuzzy'}
- yield Message(u'', '\n'.join(buf), flags=flags)
+ yield Message('', '\n'.join(buf), flags=flags)
for key in self._messages:
yield self._messages[key]
@@ -831,7 +831,7 @@ class Catalog:
if not isinstance(message.string, (list, tuple)):
fuzzy = True
message.string = tuple(
- [message.string] + ([u''] * (len(message.id) - 1))
+ [message.string] + ([''] * (len(message.id) - 1))
)
elif len(message.string) != self.num_plurals:
fuzzy = True
@@ -841,7 +841,7 @@ class Catalog:
message.string = message.string[0]
message.flags |= oldmsg.flags
if fuzzy:
- message.flags |= {u'fuzzy'}
+ message.flags |= {'fuzzy'}
self[message.id] = message
for message in template:
diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py
index 98a1ca8..de17b1e 100644
--- a/babel/messages/frontend.py
+++ b/babel/messages/frontend.py
@@ -948,7 +948,7 @@ class CommandLineInterface:
identifiers = localedata.locale_identifiers()
longest = max(len(identifier) for identifier in identifiers)
identifiers.sort()
- format = u'%%-%ds %%s' % (longest + 1)
+ format = '%%-%ds %%s' % (longest + 1)
for identifier in identifiers:
locale = Locale.parse(identifier)
print(format % (identifier, locale.english_name))
diff --git a/babel/messages/jslexer.py b/babel/messages/jslexer.py
index e6d20ae..6eab920 100644
--- a/babel/messages/jslexer.py
+++ b/babel/messages/jslexer.py
@@ -154,7 +154,7 @@ def unquote_string(string: str) -> str:
if pos < len(string):
add(string[pos:])
- return u''.join(result)
+ return ''.join(result)
def tokenize(source: str, jsx: bool = True, dotted: bool = True, template_string: bool = True, lineno: int = 1) -> Generator[Token, None, None]:
diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py
index 76d3123..a9180a7 100644
--- a/babel/messages/pofile.py
+++ b/babel/messages/pofile.py
@@ -184,7 +184,7 @@ class PoFileParser:
string = ['' for _ in range(self.catalog.num_plurals)]
for idx, translation in self.translations:
if idx >= self.catalog.num_plurals:
- self._invalid_pofile(u"", self.offset, "msg has more translations than num_plurals of catalog")
+ self._invalid_pofile("", self.offset, "msg has more translations than num_plurals of catalog")
continue
string[idx] = translation.denormalize()
string = tuple(string)
@@ -320,8 +320,8 @@ class PoFileParser:
# No actual messages found, but there was some info in comments, from which
# we'll construct an empty header message
if not self.counter and (self.flags or self.user_comments or self.auto_comments):
- self.messages.append(_NormalizedString(u'""'))
- self.translations.append([0, _NormalizedString(u'""')])
+ self.messages.append(_NormalizedString('""'))
+ self.translations.append([0, _NormalizedString('""')])
self._add_message()
def _invalid_pofile(self, line, lineno, msg) -> None:
@@ -462,7 +462,7 @@ def normalize(string: str, prefix: str = '', width: int = 76) -> str:
# separate line
buf.append(chunks.pop())
break
- lines.append(u''.join(buf))
+ lines.append(''.join(buf))
else:
lines.append(line)
else:
@@ -475,7 +475,7 @@ def normalize(string: str, prefix: str = '', width: int = 76) -> str:
if lines and not lines[-1]:
del lines[-1]
lines[-1] += '\n'
- return u'""\n' + u'\n'.join([(prefix + escape(line)) for line in lines])
+ return '""\n' + '\n'.join([(prefix + escape(line)) for line in lines])
def write_po(
@@ -586,7 +586,7 @@ def write_po(
for line in comment_header.splitlines():
lines += wraptext(line, width=width,
subsequent_indent='# ')
- comment_header = u'\n'.join(lines)
+ comment_header = '\n'.join(lines)
_write(f"{comment_header}\n")
for comment in message.user_comments:
diff --git a/babel/numbers.py b/babel/numbers.py
index 6ecd7dc..399b70b 100644
--- a/babel/numbers.py
+++ b/babel/numbers.py
@@ -324,7 +324,7 @@ def get_decimal_symbol(locale: Locale | str | None = LC_NUMERIC) -> str:
:param locale: the `Locale` object or locale identifier
"""
- return Locale.parse(locale).number_symbols.get('decimal', u'.')
+ return Locale.parse(locale).number_symbols.get('decimal', '.')
def get_plus_sign_symbol(locale: Locale | str | None = LC_NUMERIC) -> str:
@@ -335,7 +335,7 @@ def get_plus_sign_symbol(locale: Locale | str | None = LC_NUMERIC) -> str:
:param locale: the `Locale` object or locale identifier
"""
- return Locale.parse(locale).number_symbols.get('plusSign', u'+')
+ return Locale.parse(locale).number_symbols.get('plusSign', '+')
def get_minus_sign_symbol(locale: Locale | str | None = LC_NUMERIC) -> str:
@@ -346,7 +346,7 @@ def get_minus_sign_symbol(locale: Locale | str | None = LC_NUMERIC) -> str:
:param locale: the `Locale` object or locale identifier
"""
- return Locale.parse(locale).number_symbols.get('minusSign', u'-')
+ return Locale.parse(locale).number_symbols.get('minusSign', '-')
def get_exponential_symbol(locale: Locale | str | None = LC_NUMERIC) -> str:
@@ -357,7 +357,7 @@ def get_exponential_symbol(locale: Locale | str | None = LC_NUMERIC) -> str:
:param locale: the `Locale` object or locale identifier
"""
- return Locale.parse(locale).number_symbols.get('exponential', u'E')
+ return Locale.parse(locale).number_symbols.get('exponential', 'E')
def get_group_symbol(locale: Locale | str | None = LC_NUMERIC) -> str:
@@ -368,11 +368,11 @@ def get_group_symbol(locale: Locale | str | None = LC_NUMERIC) -> str:
:param locale: the `Locale` object or locale identifier
"""
- return Locale.parse(locale).number_symbols.get('group', u',')
+ return Locale.parse(locale).number_symbols.get('group', ',')
def format_number(number: float | decimal.Decimal | str, locale: Locale | str | None = LC_NUMERIC) -> str:
- u"""Return the given number formatted for a specific locale.
+ """Return the given number formatted for a specific locale.
>>> format_number(1099, locale='en_US') # doctest: +SKIP
u'1,099'
@@ -418,7 +418,7 @@ def format_decimal(
decimal_quantization: bool = True,
group_separator: bool = True,
) -> str:
- u"""Return the given decimal number formatted for a specific locale.
+ """Return the given decimal number formatted for a specific locale.
>>> format_decimal(1.2345, locale='en_US')
u'1.234'
@@ -473,7 +473,7 @@ def format_compact_decimal(
locale: Locale | str | None = LC_NUMERIC,
fraction_digits: int = 0,
) -> str:
- u"""Return the given decimal number formatted for a specific locale in compact form.
+ """Return the given decimal number formatted for a specific locale in compact form.
>>> format_compact_decimal(12345, format_type="short", locale='en_US')
u'12K'
@@ -555,7 +555,7 @@ def format_currency(
decimal_quantization: bool = True,
group_separator: bool = True,
) -> str:
- u"""Return formatted currency value.
+ """Return formatted currency value.
>>> format_currency(1099.98, 'USD', locale='en_US')
u'$1,099.98'
@@ -711,7 +711,7 @@ def format_compact_currency(
locale: Locale | str | None = LC_NUMERIC,
fraction_digits: int = 0
) -> str:
- u"""Format a number as a currency value in compact form.
+ """Format a number as a currency value in compact form.
>>> format_compact_currency(12345, 'USD', locale='en_US')
u'$12K'
@@ -916,7 +916,7 @@ def parse_decimal(string: str, locale: Locale | str | None = LC_NUMERIC, strict:
decimal_symbol = get_decimal_symbol(locale)
if not strict and (
- group_symbol == u'\xa0' and # if the grouping symbol is U+00A0 NO-BREAK SPACE,
+ group_symbol == '\xa0' and # if the grouping symbol is U+00A0 NO-BREAK SPACE,
group_symbol not in string and # and the string to be parsed does not contain it,
' ' in string # but it does contain a space instead,
):
@@ -1095,7 +1095,7 @@ class NumberPattern:
scale = 0
if '%' in ''.join(self.prefix + self.suffix):
scale = 2
- elif u'‰' in ''.join(self.prefix + self.suffix):
+ elif '‰' in ''.join(self.prefix + self.suffix):
scale = 3
return scale
@@ -1222,11 +1222,11 @@ class NumberPattern:
number if self.number_pattern != '' else '',
self.suffix[is_negative]])
- if u'¤' in retval:
- retval = retval.replace(u'¤¤¤',
+ if '¤' in retval:
+ retval = retval.replace('¤¤¤',
get_currency_name(currency, value, locale))
- retval = retval.replace(u'¤¤', currency.upper())
- retval = retval.replace(u'¤', get_currency_symbol(currency, locale))
+ retval = retval.replace('¤¤', currency.upper())
+ retval = retval.replace('¤', get_currency_symbol(currency, locale))
# remove single quotes around text, except for doubled single quotes
# which are replaced with a single quote