Skip to content

Commit ea5fa91

Browse files
Benedikt's suggestions
1 parent 7f947db commit ea5fa91

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

Lib/test/test_tools/test_i18n.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import re
55
import sys
66
import unittest
7-
from test.test_decimal import skip_expected
7+
from types import SimpleNamespace
88
from textwrap import dedent
99
from pathlib import Path
1010

@@ -519,38 +519,35 @@ def test_parse_keyword_spec(self):
519519

520520
def test_normalize_multiline(self):
521521
# required to set up normalize
522-
class NormOptions:
523-
width = 78
522+
options = SimpleNamespace(width=78)
524523
make_escapes(True)
525524

526525
s = 'multi-line\n translation'
527526
s_expected = '""\n"multi-line\\n"\n" translation"'
528527

529-
data = normalize(s, 'UTF-8', NormOptions)
528+
data = normalize(s, 'UTF-8', options)
530529
self.assertEqual(s_expected, data)
531530

532531
def test_normalize_wrap(self):
533532
# required to set up normalize
534-
class NormOptions:
535-
width = 30
533+
options = SimpleNamespace(width=30)
536534
make_escapes(True)
537535

538536
s = 'this string should be wrapped to 30 chars'
539537
s_expected = '""\n"this string should be wrapped "\n"to 30 chars"'
540538

541-
data = normalize(s, 'UTF-8', NormOptions)
539+
data = normalize(s, 'UTF-8', options)
542540
self.assertEqual(s_expected, data)
543541

544542
def test_normalize_nostr(self):
545543
# required to set up normalize
546-
class NormOptions:
547-
width = 78
544+
options = SimpleNamespace(width=30)
548545
make_escapes(True)
549546

550547
s = ''
551548
s_expected = '""'
552549

553-
data = normalize(s, 'UTF-8', NormOptions)
550+
data = normalize(s, 'UTF-8', options)
554551
self.assertEqual(s_expected, data)
555552

556553

Tools/i18n/pygettext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,13 @@ def escape_ascii(s, encoding):
213213
def escape_nonascii(s, encoding):
214214
return ''.join(escapes[b] for b in s.encode(encoding))
215215

216+
space_splitter = re.compile(r'(\s+)').split
216217

217218
def normalize(s, encoding, options):
218219
# This converts the various Python string types into a format that is
219220
# appropriate for .po files, namely much closer to C style,
220221
# while wrapping to options.width.
221222
lines = []
222-
space_splitter = re.compile(r'(\s+)').split
223223
for line in s.splitlines(True):
224224
if len(escape(line, encoding)) > options.width:
225225
words = space_splitter(line)

0 commit comments

Comments
 (0)