Closed aaronspring closed 2 years ago
Thanks @aaronspring . I'll have a look.
One thing I've found works for these is to use r"""
for docstrings. Let me see whether that works in this case. Either way, this should be a nicer experience than it currently is
FWIW this does fix the immediate problem:
diff --git a/examples/escapes.py b/examples/escapes.py
index 97f7d2f..17f8b9d 100644
--- a/examples/escapes.py
+++ b/examples/escapes.py
@@ -1,5 +1,5 @@
def func(a, b):
- """
+ r"""
Example:
>>> import xarray as xr
>>> func(xr.DataArray([5], dims='a'), xr.DataArray([1], dims='a'))
We could at least check for the r
/ insert an r
.
But would you actually prefer that the \n
are newlines rather than \n
characters? I could imagine that's clearer.
~I'm guessing this behavior is something to do with how we print the repr in xarray, since normally printing \n
does give us an actual new line:~
>>> print("testing\ntesting")
testing
testing
Edit: it's that the arrays are atrs so that part is up to xarray, and xarray is probably doing the correct thing for reprs within attrs
thanks for the r"""doc strings"""
that works
But would you actually prefer that the \n are newlines rather than \n characters? I could imagine that's clearer.
I dont have an opinion
Assume a function with doctest where the return create a linebreak
\n
:pytest --doctest-modules file.py --accept
adds the expected:Usually I expect that I can run
pytest --doctest-modules file.py --accept
and all doctests pass. Now they dont because a single\
is present but docstrings somehow expect\\n
. I get an error message:Manually correcting
\n
to\\n
lets tests pass:So would it be possible to add a small correction
.replace("\n", "\\n")
topytest-accept
? Probably\n
is not the only issue here.