File tree 2 files changed +25
-5
lines changed
2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 3
3
4
4
import functools
5
5
import re
6
+ import sys
6
7
import typing as ty
7
8
import warnings
9
+ from textwrap import dedent
8
10
9
11
if ty .TYPE_CHECKING : # pragma: no cover
10
12
T = ty .TypeVar ('T' )
11
13
P = ty .ParamSpec ('P' )
12
14
13
15
_LEADING_WHITE = re .compile (r'^(\s*)' )
14
16
17
+
18
+ def _dedent_docstring (docstring ):
19
+ """Compatibility with Python 3.13+.
20
+
21
+ xref: https://github.com/python/cpython/issues/81283
22
+ """
23
+ return '\n ' .join ([dedent (line ) for line in docstring .split ('\n ' )])
24
+
25
+
15
26
TESTSETUP = """
16
27
17
28
.. testsetup::
32
43
33
44
"""
34
45
46
+ if sys .version_info >= (3 , 13 ):
47
+ TESTSETUP = _dedent_docstring (TESTSETUP )
48
+ TESTCLEANUP = _dedent_docstring (TESTCLEANUP )
49
+
35
50
36
51
class ExpiredDeprecationError (RuntimeError ):
37
52
"""Error for expired deprecation
Original file line number Diff line number Diff line change 14
14
Deprecator ,
15
15
ExpiredDeprecationError ,
16
16
_add_dep_doc ,
17
+ _dedent_docstring ,
17
18
_ensure_cr ,
18
19
)
19
20
20
21
from ..testing import clear_and_catch_warnings
21
22
22
23
_OWN_MODULE = sys .modules [__name__ ]
23
24
25
+ func_docstring = (
26
+ f'A docstring\n \n foo\n \n { indent (TESTSETUP , " " , lambda x : True )} '
27
+ f' Some text\n { indent (TESTCLEANUP , " " , lambda x : True )} '
28
+ )
29
+
30
+ if sys .version_info >= (3 , 13 ):
31
+ func_docstring = _dedent_docstring (func_docstring )
32
+
24
33
25
34
def test__ensure_cr ():
26
35
# Make sure text ends with carriage return
@@ -92,11 +101,7 @@ def test_dep_func(self):
92
101
with pytest .deprecated_call () as w :
93
102
assert func (1 , 2 ) is None
94
103
assert len (w ) == 1
95
- assert (
96
- func .__doc__
97
- == f'A docstring\n \n foo\n \n { indent (TESTSETUP , " " , lambda x : True )} '
98
- f' Some text\n { indent (TESTCLEANUP , " " , lambda x : True )} '
99
- )
104
+ assert func .__doc__ == func_docstring
100
105
101
106
# Try some since and until versions
102
107
func = dec ('foo' , '1.1' )(func_no_doc )
You can’t perform that action at this time.
0 commit comments