Erotemic / xdoctest

A rewrite of Python's builtin doctest module (with pytest plugin integration) with AST instead of REGEX.
Apache License 2.0
205 stars 12 forks source link

Fix python3.13 deprecation warning #157

Closed sdb9696 closed 1 month ago

sdb9696 commented 1 month ago

Hi, we've been updating our CI to work with python3.13 in preparation for the upcoming release in October. While doing so we received DeprecationWarnings from checker.py passing count to re.sub as a positional argument. It seems in python3.13 this is deprecated due to confusion between flags and count.

This PR updates checker.py to pass re.MULTILINE to re.sub with a keyword flags argument. I think the original code intended for this to be a flag rather than a count. When I tested this with re.MULTILINE passed as the 4th argument it interpreted it as an integer of 8 and only replaces 8 occurrences of BLANKLINE_MAKER.

>>> from xdoctest.checker import remove_blankline_marker
>>> BLANKLINE_MARKER = '<BLANKLINE>'
>>> BLANKLINE_MARKER_ARR = [BLANKLINE_MARKER] * 10
>>> text='Foo\n'.join(BLANKLINE_MARKER_ARR )
>>> remove_blankline_marker(text)
'\nFoo\nFoo\nFoo\nFoo\nFoo\nFoo\nFoo\nFoo\n<BLANKLINE>Foo\n<BLANKLINE>'

Running the test suite against main on python 3.13:

tests/test_checker.py::test_visible_lines
tests/test_checker.py::test_blankline_accept
tests/test_checker.py::test_blankline_failcase
tests/test_doctest_example.py::test_failed_assign_want
tests/test_doctest_example.py::test_failed_assign_want
tests/test_doctest_example.py::test_eval_expr_capture
tests/test_traceback.py::test_lineno_failcase_gotwant
tests/test_traceback.py::test_lineno_failcase_gotwant
  ~/xdoctest/src/xdoctest/checker.py:637: DeprecationWarning: 'count' is passed as positional argument
    new_text = re.sub(blankline_pattern, '\n', text, re.MULTILINE)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
== 296 passed, 23 skipped, 8 warnings in 43.77s ==

Running the test suite against this PR on python 3.13:

== 296 passed, 23 skipped in 44.35s ==
Erotemic commented 1 month ago

Thanks for catching this. Can you add a "Fixed" entry to CHANGELOG.md?

I will merge and push a release this fix shortly.

sdb9696 commented 1 month ago

Thanks for catching this. Can you add a "Fixed" entry to CHANGELOG.md?

I will merge and push a release this fix shortly.

That's done