Skip to content

Commit fd480bb

Browse files
committed
Strip any leading '#' and whitespace from comments
1 parent feb1145 commit fd480bb

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Lib/test/test_tools/i18n_data/comments.pot

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,10 @@ msgstr ""
101101
msgid "thud"
102102
msgstr ""
103103

104+
#. i18n: This is a translator comment
105+
#. i18n: This is another translator comment
106+
#. i18n: This is yet another translator comment
107+
#: comments.py:78
108+
msgid "foos"
109+
msgstr ""
110+

Lib/test/test_tools/i18n_data/comments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,9 @@
7070
# i18n: This is a translator comment
7171
_('xyzzy')
7272
_('thud')
73+
74+
75+
## i18n: This is a translator comment
76+
# # i18n: This is another translator comment
77+
### ### i18n: This is yet another translator comment
78+
_('foos')

Tools/i18n/pygettext.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
import importlib.machinery
145145
import importlib.util
146146
import os
147+
import re
147148
import sys
148149
import time
149150
import tokenize
@@ -329,7 +330,9 @@ def get_source_comments(source):
329330
comments = {}
330331
for token in tokenize.tokenize(BytesIO(source).readline):
331332
if token.type == tokenize.COMMENT:
332-
comments[token.start[0]] = token.string.removeprefix('#').strip()
333+
# Remove any leading combination of '#' and whitespace
334+
comment = re.sub(r'^[#\s]+', '', token.string)
335+
comments[token.start[0]] = comment
333336
return comments
334337

335338

0 commit comments

Comments
 (0)