Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove u string prefix from docs #1174

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 62 additions & 62 deletions babel/core.py

Large diffs are not rendered by default.

170 changes: 85 additions & 85 deletions babel/dates.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions babel/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def format_list(
Format the items in `lst` as a list.

>>> format_list(['apples', 'oranges', 'pears'], locale='en')
u'apples, oranges, and pears'
'apples, oranges, and pears'
>>> format_list(['apples', 'oranges', 'pears'], locale='zh')
u'apples\u3001oranges\u548cpears'
'apples、oranges和pears'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do some of the changes have escaped sequences replaced with characters and others don't? 🤔

I think I'd rather not change any escape sequences to the unescaped versions, just so it's easy to see e.g. the difference between - – — 😄

Copy link
Author

@verhovsky verhovsky Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I said,

I also updated some strings to include the character instead of \u and \x literals since that's what the Python 3 REPL does

I don't think I missed any, some sequences are escaped because they're unprintable characters that are escaped by the Python REPL, like \u2009. I think for console examples the example should print exactly what the REPL outputs, we could argue about what to put in the code that causes the REPL to print that string though.

Like we can have

>>> 'apples\u3001oranges\u548cpears'
'apples、oranges和pears'

but we definitely shouldn't have

>>> 'apples\u3001oranges\u548cpears'
'apples\u3001oranges\u548cpears'

because that's not what actually happens in the REPL.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also separated the 3 things I did into 3 separate commits for easier review.

>>> format_list(['omena', 'peruna', 'aplari'], style='or', locale='fi')
u'omena, peruna tai aplari'
'omena, peruna tai aplari'

Not all styles are necessarily available in all locales.
The function will attempt to fall back to replacement styles according to the rules
Expand Down
2 changes: 1 addition & 1 deletion babel/localedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def load(name: os.PathLike[str] | str, merge_inherited: bool = True) -> dict[str

>>> d = load('en_US')
>>> d['languages']['sv']
u'Swedish'
'Swedish'

Note that the results are cached, and subsequent requests for the same
locale return the same dictionary:
Expand Down
30 changes: 15 additions & 15 deletions babel/messages/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,19 +654,19 @@ def __setitem__(self, id: _MessageID, message: Message) -> None:
"""Add or update the message with the specified ID.

>>> catalog = Catalog()
>>> catalog[u'foo'] = Message(u'foo')
>>> catalog[u'foo']
<Message u'foo' (flags: [])>
>>> catalog['foo'] = Message('foo')
>>> catalog['foo']
<Message 'foo' (flags: [])>

If a message with that ID is already in the catalog, it is updated
to include the locations and flags of the new message.

>>> catalog = Catalog()
>>> catalog[u'foo'] = Message(u'foo', locations=[('main.py', 1)])
>>> catalog[u'foo'].locations
>>> catalog['foo'] = Message('foo', locations=[('main.py', 1)])
>>> catalog['foo'].locations
[('main.py', 1)]
>>> catalog[u'foo'] = Message(u'foo', locations=[('utils.py', 5)])
>>> catalog[u'foo'].locations
>>> catalog['foo'] = Message('foo', locations=[('utils.py', 5)])
>>> catalog['foo'].locations
[('main.py', 1), ('utils.py', 5)]

:param id: the message ID
Expand Down Expand Up @@ -713,10 +713,10 @@ def add(
"""Add or update the message with the specified ID.

>>> catalog = Catalog()
>>> catalog.add(u'foo')
>>> catalog.add('foo')
<Message ...>
>>> catalog[u'foo']
<Message u'foo' (flags: [])>
>>> catalog['foo']
<Message 'foo' (flags: [])>

This method simply constructs a `Message` object with the given
arguments and invokes `__setitem__` with that object.
Expand Down Expand Up @@ -792,11 +792,11 @@ def update(
>>> template.add(('salad', 'salads'), locations=[('util.py', 42)])
<Message ...>
>>> catalog = Catalog(locale='de_DE')
>>> catalog.add('blue', u'blau', locations=[('main.py', 98)])
>>> catalog.add('blue', 'blau', locations=[('main.py', 98)])
<Message ...>
>>> catalog.add('head', u'Kopf', locations=[('util.py', 33)])
>>> catalog.add('head', 'Kopf', locations=[('util.py', 33)])
<Message ...>
>>> catalog.add(('salad', 'salads'), (u'Salat', u'Salate'),
>>> catalog.add(('salad', 'salads'), ('Salat', 'Salate'),
... locations=[('util.py', 38)])
<Message ...>

Expand All @@ -811,13 +811,13 @@ def update(

>>> msg2 = catalog['blue']
>>> msg2.string
u'blau'
'blau'
>>> msg2.locations
[('main.py', 100)]

>>> msg3 = catalog['salad']
>>> msg3.string
(u'Salat', u'Salate')
('Salat', 'Salate')
>>> msg3.locations
[('util.py', 42)]

Expand Down
2 changes: 1 addition & 1 deletion babel/messages/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def extract(
>>> from io import BytesIO
>>> for message in extract('python', BytesIO(source)):
... print(message)
(3, u'Hello, world!', [], None)
(3, 'Hello, world!', [], None)

:param method: an extraction method (a callable), or
a string specifying the extraction method (.e.g. "python");
Expand Down
16 changes: 8 additions & 8 deletions babel/messages/mofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def write_mo(fileobj: SupportsWrite[bytes], catalog: Catalog, use_fuzzy: bool =
>>> catalog = Catalog(locale='en_US')
>>> catalog.add('foo', 'Voh')
<Message ...>
>>> catalog.add((u'bar', u'baz'), (u'Bahr', u'Batz'))
>>> catalog.add(('bar', 'baz'), ('Bahr', 'Batz'))
<Message ...>
>>> catalog.add('fuz', 'Futz', flags=['fuzzy'])
<Message ...>
Expand All @@ -133,19 +133,19 @@ def write_mo(fileobj: SupportsWrite[bytes], catalog: Catalog, use_fuzzy: bool =
... translations.ugettext = translations.gettext
... translations.ungettext = translations.ngettext
>>> translations.ugettext('foo')
u'Voh'
'Voh'
>>> translations.ungettext('bar', 'baz', 1)
u'Bahr'
'Bahr'
>>> translations.ungettext('bar', 'baz', 2)
u'Batz'
'Batz'
>>> translations.ugettext('fuz')
u'fuz'
'fuz'
>>> translations.ugettext('Fizz')
u'Fizz'
'Fizz'
>>> translations.ugettext('Fuzz')
u'Fuzz'
'Fuzz'
>>> translations.ugettext('Fuzzes')
u'Fuzzes'
'Fuzzes'

:param fileobj: the file-like object to write to
:param catalog: the `Catalog` instance
Expand Down
14 changes: 7 additions & 7 deletions babel/messages/pofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,12 @@ def read_po(
... print((message.id, message.string))
... print(' ', (message.locations, sorted(list(message.flags))))
... print(' ', (message.user_comments, message.auto_comments))
(u'foo %(name)s', u'quux %(name)s')
([(u'main.py', 1)], [u'fuzzy', u'python-format'])
('foo %(name)s', 'quux %(name)s')
([('main.py', 1)], ['fuzzy', 'python-format'])
([], [])
((u'bar', u'baz'), (u'bar', u'baaz'))
([(u'main.py', 3)], [])
([u'A user comment'], [u'An auto comment'])
(('bar', 'baz'), ('bar', 'baaz'))
([('main.py', 3)], [])
(['A user comment'], ['An auto comment'])

.. versionadded:: 1.0
Added support for explicit charset argument.
Expand Down Expand Up @@ -557,10 +557,10 @@ def write_po(
message catalog to the provided file-like object.

>>> catalog = Catalog()
>>> catalog.add(u'foo %(name)s', locations=[('main.py', 1)],
>>> catalog.add('foo %(name)s', locations=[('main.py', 1)],
... flags=('fuzzy',))
<Message...>
>>> catalog.add((u'bar', u'baz'), locations=[('main.py', 3)])
>>> catalog.add(('bar', 'baz'), locations=[('main.py', 3)])
<Message...>
>>> from io import BytesIO
>>> buf = BytesIO()
Expand Down
Loading