actual = stdout.getvalue()
self.assertEqual(actual, expected)
+ def test_non_ascii_character_in_docstring(self):
+ block = """
+ module test
+ test.fn
+ a: int
+ á param docstring
+ docstring fü bár baß
+ """
+ with support.captured_stdout() as stdout:
+ self.parse(block)
+ # The line numbers are off; this is a known limitation.
+ expected = dedent("""\
+ Warning on line 0:
+ Non-ascii characters are not allowed in docstrings: 'á'
+ Warning on line 0:
+ Non-ascii characters are not allowed in docstrings: 'ü', 'á', 'ß'
+ """)
+ self.assertEqual(stdout.getvalue(), expected)
+
class ClinicExternalTest(TestCase):
maxDiff = None
self,
f: Function
) -> str:
- if re.search(r'[^\x00-\x7F]', f.docstring):
- warn("Non-ascii character appear in docstring.")
-
text, add, output = _text_accumulator()
# turn docstring into a properly quoted C string
for line in f.docstring.split('\n'):
def docstring_append(self, obj: Function | Parameter, line: str) -> None:
"""Add a rstripped line to the current docstring."""
+ matches = re.finditer(r'[^\x00-\x7F]', line)
+ if offending := ", ".join([repr(m[0]) for m in matches]):
+ warn("Non-ascii characters are not allowed in docstrings:",
+ offending)
+
docstring = obj.docstring
if docstring:
docstring += "\n"