Skip to content

Commit 4e47450

Browse files
authored
Merge branch 'main' into doc-namespace-package
2 parents b6b4c09 + 303043f commit 4e47450

File tree

16 files changed

+158
-141
lines changed

16 files changed

+158
-141
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ jobs:
658658
build_asan,
659659
build_tsan,
660660
test_hypothesis,
661+
cross-build-linux,
661662
'
662663
|| ''
663664
}}

Doc/c-api/unicode.rst

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,8 @@ the Python configuration.
256256
257257
.. c:function:: int Py_UNICODE_ISPRINTABLE(Py_UCS4 ch)
258258
259-
Return ``1`` or ``0`` depending on whether *ch* is a printable character.
260-
Nonprintable characters are those characters defined in the Unicode character
261-
database as "Other" or "Separator", excepting the ASCII space (0x20) which is
262-
considered printable. (Note that printable characters in this context are
263-
those which should not be escaped when :func:`repr` is invoked on a string.
264-
It has no bearing on the handling of strings written to :data:`sys.stdout` or
265-
:data:`sys.stderr`.)
259+
Return ``1`` or ``0`` depending on whether *ch* is a printable character,
260+
in the sense of :meth:`str.isprintable`.
266261
267262
268263
These APIs can be used for fast direct character conversions:

Doc/library/stdtypes.rst

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,13 +2012,19 @@ expression support in the :mod:`re` module).
20122012

20132013
.. method:: str.isprintable()
20142014

2015-
Return ``True`` if all characters in the string are printable or the string is
2016-
empty, ``False`` otherwise. Nonprintable characters are those characters defined
2017-
in the Unicode character database as "Other" or "Separator", excepting the
2018-
ASCII space (0x20) which is considered printable. (Note that printable
2019-
characters in this context are those which should not be escaped when
2020-
:func:`repr` is invoked on a string. It has no bearing on the handling of
2021-
strings written to :data:`sys.stdout` or :data:`sys.stderr`.)
2015+
Return true if all characters in the string are printable, false if it
2016+
contains at least one non-printable character.
2017+
2018+
Here "printable" means the character is suitable for :func:`repr` to use in
2019+
its output; "non-printable" means that :func:`repr` on built-in types will
2020+
hex-escape the character. It has no bearing on the handling of strings
2021+
written to :data:`sys.stdout` or :data:`sys.stderr`.
2022+
2023+
The printable characters are those which in the Unicode character database
2024+
(see :mod:`unicodedata`) have a general category in group Letter, Mark,
2025+
Number, Punctuation, or Symbol (L, M, N, P, or S); plus the ASCII space 0x20.
2026+
Nonprintable characters are those in group Separator or Other (Z or C),
2027+
except the ASCII space.
20222028

20232029

20242030
.. method:: str.isspace()

Lib/mimetypes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def add_type(self, type, ext, strict=True):
9090
list of standard types, else to the list of non-standard
9191
types.
9292
"""
93+
if not type:
94+
return
9395
self.types_map[strict][ext] = type
9496
exts = self.types_map_inv[strict].setdefault(type, [])
9597
if ext not in exts:

Lib/test/test_gettext.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
# TODO:
1212
# - Add new tests, for example for "dgettext"
13-
# - Remove dummy tests, for example testing for single and double quotes
14-
# has no sense, it would have if we were testing a parser (i.e. pygettext)
1513
# - Tests should have only one assert.
1614

1715
GNU_MO_DATA = b'''\
@@ -175,30 +173,6 @@ def test_some_translations_with_context(self):
175173
eq(pgettext('my other context', 'nudge nudge'),
176174
'wink wink (in "my other context")')
177175

178-
def test_double_quotes(self):
179-
eq = self.assertEqual
180-
# double quotes
181-
eq(_("albatross"), 'albatross')
182-
eq(_("mullusk"), 'bacon')
183-
eq(_(r"Raymond Luxury Yach-t"), 'Throatwobbler Mangrove')
184-
eq(_(r"nudge nudge"), 'wink wink')
185-
186-
def test_triple_single_quotes(self):
187-
eq = self.assertEqual
188-
# triple single quotes
189-
eq(_('''albatross'''), 'albatross')
190-
eq(_('''mullusk'''), 'bacon')
191-
eq(_(r'''Raymond Luxury Yach-t'''), 'Throatwobbler Mangrove')
192-
eq(_(r'''nudge nudge'''), 'wink wink')
193-
194-
def test_triple_double_quotes(self):
195-
eq = self.assertEqual
196-
# triple double quotes
197-
eq(_("""albatross"""), 'albatross')
198-
eq(_("""mullusk"""), 'bacon')
199-
eq(_(r"""Raymond Luxury Yach-t"""), 'Throatwobbler Mangrove')
200-
eq(_(r"""nudge nudge"""), 'wink wink')
201-
202176
def test_multiline_strings(self):
203177
eq = self.assertEqual
204178
# multiline strings
@@ -285,30 +259,6 @@ def test_some_translations_with_context_and_domain(self):
285259
eq(gettext.dpgettext('gettext', 'my other context', 'nudge nudge'),
286260
'wink wink (in "my other context")')
287261

288-
def test_double_quotes(self):
289-
eq = self.assertEqual
290-
# double quotes
291-
eq(self._("albatross"), 'albatross')
292-
eq(self._("mullusk"), 'bacon')
293-
eq(self._(r"Raymond Luxury Yach-t"), 'Throatwobbler Mangrove')
294-
eq(self._(r"nudge nudge"), 'wink wink')
295-
296-
def test_triple_single_quotes(self):
297-
eq = self.assertEqual
298-
# triple single quotes
299-
eq(self._('''albatross'''), 'albatross')
300-
eq(self._('''mullusk'''), 'bacon')
301-
eq(self._(r'''Raymond Luxury Yach-t'''), 'Throatwobbler Mangrove')
302-
eq(self._(r'''nudge nudge'''), 'wink wink')
303-
304-
def test_triple_double_quotes(self):
305-
eq = self.assertEqual
306-
# triple double quotes
307-
eq(self._("""albatross"""), 'albatross')
308-
eq(self._("""mullusk"""), 'bacon')
309-
eq(self._(r"""Raymond Luxury Yach-t"""), 'Throatwobbler Mangrove')
310-
eq(self._(r"""nudge nudge"""), 'wink wink')
311-
312262
def test_multiline_strings(self):
313263
eq = self.assertEqual
314264
# multiline strings

Lib/test/test_peepholer.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,83 @@ def test_folding_subscript(self):
535535
self.assertInBytecode(code, 'BINARY_OP', argval=subscr_argval)
536536
self.check_lnotab(code)
537537

538+
def test_constant_folding_remove_nop_location(self):
539+
sources = [
540+
"""
541+
(-
542+
-
543+
-
544+
1)
545+
""",
546+
547+
"""
548+
(1
549+
+
550+
2
551+
+
552+
3)
553+
""",
554+
555+
"""
556+
(1,
557+
2,
558+
3)[0]
559+
""",
560+
561+
"""
562+
[1,
563+
2,
564+
3]
565+
""",
566+
567+
"""
568+
{1,
569+
2,
570+
3}
571+
""",
572+
573+
"""
574+
1 in [
575+
1,
576+
2,
577+
3
578+
]
579+
""",
580+
581+
"""
582+
1 in {
583+
1,
584+
2,
585+
3
586+
}
587+
""",
588+
589+
"""
590+
for _ in [1,
591+
2,
592+
3]:
593+
pass
594+
""",
595+
596+
"""
597+
for _ in [1,
598+
2,
599+
x]:
600+
pass
601+
""",
602+
603+
"""
604+
for _ in {1,
605+
2,
606+
3}:
607+
pass
608+
"""
609+
]
610+
611+
for source in sources:
612+
code = compile(textwrap.dedent(source), '', 'single')
613+
self.assertNotInBytecode(code, 'NOP')
614+
538615
def test_in_literal_list(self):
539616
def containtest():
540617
return x in [a, b]

Lib/test/test_str.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,15 @@ def test_isprintable(self):
853853
self.assertTrue('\U0001F46F'.isprintable())
854854
self.assertFalse('\U000E0020'.isprintable())
855855

856+
@support.requires_resource('cpu')
857+
def test_isprintable_invariant(self):
858+
for codepoint in range(sys.maxunicode + 1):
859+
char = chr(codepoint)
860+
category = unicodedata.category(char)
861+
self.assertEqual(char.isprintable(),
862+
category[0] not in ('C', 'Z')
863+
or char == ' ')
864+
856865
def test_surrogates(self):
857866
for s in ('a\uD800b\uDFFF', 'a\uDFFFb\uD800',
858867
'a\uD800b\uDFFFa', 'a\uDFFFb\uD800a'):

Lib/test/test_tools/test_i18n.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ def test_files_list(self):
413413
self.assertIn(f'msgid "{text2}"', data)
414414
self.assertNotIn(text3, data)
415415

416+
def test_help_text(self):
417+
"""Test that the help text is displayed."""
418+
res = assert_python_ok(self.script, '--help')
419+
self.assertEqual(res.out, b'')
420+
self.assertIn(b'pygettext -- Python equivalent of xgettext(1)', res.err)
421+
416422
def test_error_messages(self):
417423
"""Test that pygettext outputs error messages to stderr."""
418424
stderr = self.get_stderr(dedent('''\
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :func:`mimetypes.guess_type` to use default mapping for empty
2+
``Content-Type`` in registry.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix the keyword entry in the help output of :program:`pygettext`.

0 commit comments

Comments
 (0)