Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove backslash hack in doctest #39186

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
8 changes: 3 additions & 5 deletions src/doc/en/developer/coding_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1106,12 +1106,10 @@ written.
The :ref:`doctest fixer <section-fixdoctests-optional-needs>` uses
tab stops at columns 48, 56, 64, ... for these tags.

- **Split long lines:** You may want to split long lines of code with a
backslash. Note: this syntax is non-standard and may be removed in the
future::
- **Split long lines:** Standard Python rules apply. For example::

sage: n = 123456789123456789123456789\
....: 123456789123456789123456789
sage: n = (123456789123456789123456789 +
....: 123456789123456789123456789)
sage: n.is_prime()
False

Expand Down
2 changes: 1 addition & 1 deletion src/doc/en/thematic_tutorials/lie/branching_rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ we could accomplish the branching in two steps, thus::
sage: A1xA1 = WeylCharacterRing("A1xA1", style="coroots")
sage: reps = [A3(fw) for fw in A3.fundamental_weights()]
sage: [pi.branch(C2, rule="symmetric").branch(B2, rule="isomorphic"). \
branch(D2, rule="extended").branch(A1xA1, rule="isomorphic") for pi in reps]
....: branch(D2, rule="extended").branch(A1xA1, rule="isomorphic") for pi in reps]
[A1xA1(1,0) + A1xA1(0,1), 2*A1xA1(0,0) + A1xA1(1,1), A1xA1(1,0) + A1xA1(0,1)]

As you can see, we've redone the branching rather circuitously this
Expand Down
4 changes: 2 additions & 2 deletions src/doc/en/thematic_tutorials/lie/crystals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ irreducible crystal. We can make four such crystals::
sage: C = crystals.Letters("A2")
sage: T = crystals.TensorProduct(C,C,C)
sage: [T1,T2,T3,T4] = \
[crystals.TensorProduct(C,C,C,generators=[v]) for v in T.highest_weight_vectors()]
....: [crystals.TensorProduct(C,C,C,generators=[v]) for v in T.highest_weight_vectors()]
sage: [B.cardinality() for B in [T1,T2,T3,T4]]
[10, 8, 8, 1]
sage: [B.character(A2) for B in [T1,T2,T3,T4]]
Expand All @@ -754,7 +754,7 @@ We see that two of these crystals are isomorphic, with character
sage: C = crystals.Letters("A2")
sage: T = crystals.TensorProduct(C,C,C)
sage: [T1,T2,T3,T4] = \
[crystals.TensorProduct(C,C,C,generators=[v]) for v in T.highest_weight_vectors()]
....: [crystals.TensorProduct(C,C,C,generators=[v]) for v in T.highest_weight_vectors()]
sage: T1.plot()
Graphics object consisting of 35 graphics primitives
sage: T2.plot()
Expand Down
4 changes: 2 additions & 2 deletions src/doc/en/thematic_tutorials/sandpile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ dict (configuration)
EXAMPLES::

sage: g = {0:{},1:{0:1,3:1,4:1},2:{0:1,3:1,5:1}, \
3:{2:1,5:1},4:{1:1,3:1},5:{2:1,3:1}}
....: 3:{2:1,5:1},4:{1:1,3:1},5:{2:1,3:1}}
sage: S = Sandpile(g,0)
sage: S.burning_config()
{1: 2, 2: 0, 3: 1, 4: 1, 5: 0}
Expand Down Expand Up @@ -1226,7 +1226,7 @@ OUTPUT: dict
EXAMPLES::

sage: g = {0:{},1:{0:1,3:1,4:1},2:{0:1,3:1,5:1},\
3:{2:1,5:1},4:{1:1,3:1},5:{2:1,3:1}}
....: 3:{2:1,5:1},4:{1:1,3:1},5:{2:1,3:1}}
sage: S = Sandpile(g,0)
sage: S.burning_config()
{1: 2, 2: 0, 3: 1, 4: 1, 5: 0}
Expand Down
6 changes: 3 additions & 3 deletions src/sage/coding/delsarte_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def delsarte_bound_additive_hamming_space(n, d, q, d_star=1, q_base=0, return_da
sage: codes.bounds.delsarte_bound_additive_hamming_space(11, 6, 2)
3
sage: a,p,val = codes.bounds.delsarte_bound_additive_hamming_space(\
11, 6, 2, return_data=True)
....: 11, 6, 2, return_data=True)
sage: [j for i,j in p.get_values(a).items()]
[1, 0, 0, 0, 0, 0, 5, 2, 0, 0, 0, 0]

Expand All @@ -514,13 +514,13 @@ def delsarte_bound_additive_hamming_space(n, d, q, d_star=1, q_base=0, return_da
TESTS::

sage: a,p,x = codes.bounds.delsarte_bound_additive_hamming_space(\
19,15,7,return_data=True,isinteger=True)
....: 19,15,7,return_data=True,isinteger=True)
sage: [j for i,j in p.get_values(a).items()]
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 307, 0, 0, 1, 34]
sage: codes.bounds.delsarte_bound_additive_hamming_space(19,15,7,solver='glpk')
3
sage: codes.bounds.delsarte_bound_additive_hamming_space(\
19,15,7, isinteger=True, solver='glpk')
....: 19,15,7, isinteger=True, solver='glpk')
3
"""
from sage.numerical.mip import MIPSolverException
Expand Down
8 changes: 4 additions & 4 deletions src/sage/coding/extended_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def parity_check_matrix(self):
EXAMPLES::

sage: C = LinearCode(matrix(GF(2),[[1,0,0,1,1],\
[0,1,0,1,0],\
[0,0,1,1,1]]))
....: [0,1,0,1,0],\
....: [0,0,1,1,1]]))
sage: C.parity_check_matrix()
[1 0 1 0 1]
[0 1 0 1 1]
Expand Down Expand Up @@ -259,8 +259,8 @@ def generator_matrix(self):
EXAMPLES::

sage: C = LinearCode(matrix(GF(2),[[1,0,0,1,1],\
[0,1,0,1,0],\
[0,0,1,1,1]]))
....: [0,1,0,1,0],\
....: [0,0,1,1,1]]))
sage: Ce = codes.ExtendedCode(C)
sage: E = codes.encoders.ExtendedCodeExtendedMatrixEncoder(Ce)
sage: E.generator_matrix()
Expand Down
24 changes: 12 additions & 12 deletions src/sage/coding/information_set_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ def decode(self, r):
EXAMPLES::

sage: M = matrix(GF(2), [[1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0],\
[0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1],\
[0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0],\
[0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1],\
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1]])
....: [0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1],\
....: [0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0],\
....: [0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1],\
....: [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1]])
sage: C = codes.LinearCode(M)
sage: from sage.coding.information_set_decoder import LeeBrickellISDAlgorithm
sage: A = LeeBrickellISDAlgorithm(C, (2,2))
Expand Down Expand Up @@ -448,10 +448,10 @@ def decode(self, r):
EXAMPLES::

sage: M = matrix(GF(2), [[1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0],\
[0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1],\
[0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0],\
[0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1],\
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1]])
....: [0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1],\
....: [0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0],\
....: [0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1],\
....: [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1]])
sage: C = codes.LinearCode(M)
sage: from sage.coding.information_set_decoder import LeeBrickellISDAlgorithm
sage: A = LeeBrickellISDAlgorithm(C, (2,2))
Expand Down Expand Up @@ -929,10 +929,10 @@ def decode_to_code(self, r):
EXAMPLES::

sage: M = matrix(GF(2), [[1,0,0,0,0,0,1,0,1,0,1,1,0,0,1],\
[0,1,0,0,0,1,1,1,1,0,0,0,0,1,1],\
[0,0,1,0,0,0,0,1,0,1,1,1,1,1,0],\
[0,0,0,1,0,0,1,0,1,0,0,0,1,1,0],\
[0,0,0,0,1,0,0,0,1,0,1,1,0,1,0]])
....: [0,1,0,0,0,1,1,1,1,0,0,0,0,1,1],\
....: [0,0,1,0,0,0,0,1,0,1,1,1,1,1,0],\
....: [0,0,0,1,0,0,1,0,1,0,0,0,1,1,0],\
....: [0,0,0,0,1,0,0,0,1,0,1,1,0,1,0]])
sage: C = LinearCode(M)
sage: c = C.random_element()
sage: Chan = channels.StaticErrorRateChannel(C.ambient_space(), 2)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/coding/linear_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class should inherit from this class. Also ``AbstractLinearCode`` should never
A ``LinearCode`` is instantiated by providing a generator matrix::

sage: M = matrix(GF(2), [[1, 0, 0, 1, 0],\
[0, 1, 0, 1, 1],\
[0, 0, 1, 1, 1]])
....: [0, 1, 0, 1, 1],\
....: [0, 0, 1, 1, 1]])
sage: C = codes.LinearCode(M)
sage: C
[5, 3] linear code over GF(2)
Expand Down
46 changes: 23 additions & 23 deletions src/sage/coding/linear_code_no_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def systematic_generator_matrix(self, systematic_positions=None):
EXAMPLES::

sage: G = matrix(GF(3), [[ 1, 2, 1, 0],\
[ 2, 1, 1, 1]])
....: [ 2, 1, 1, 1]])
sage: C = LinearCode(G)
sage: C.generator_matrix()
[1 2 1 0]
Expand Down Expand Up @@ -577,8 +577,8 @@ def standard_form(self, return_permutation=True):
sage: Cs is C
True
sage: C = LinearCode(matrix(GF(2), [[1,0,0,0,1,1,0],\
[0,1,0,1,0,1,0],\
[0,0,0,0,0,0,1]]))
....: [0,1,0,1,0,1,0],\
....: [0,0,0,0,0,0,1]]))
sage: Cs, p = C.standard_form()
sage: p
[1, 2, 7, 3, 4, 5, 6]
Expand Down Expand Up @@ -627,7 +627,7 @@ def redundancy_matrix(self):
[1 1 0]
[1 1 1]
sage: C = LinearCode(matrix(GF(3),2,[1,2,0,\
2,1,1]))
....: 2,1,1]))
sage: C.systematic_generator_matrix()
[1 2 0]
[0 0 1]
Expand Down Expand Up @@ -1053,9 +1053,9 @@ class LinearCodeSystematicEncoder(Encoder):

sage: LCSE = codes.encoders.LinearCodeSystematicEncoder
sage: G = Matrix(GF(2), [[1,1,1,0,0,0,0,0],\
[1,0,0,1,1,0,0,0],\
[0,1,0,1,0,1,0,0],\
[1,1,0,1,0,0,1,1]])
....: [1,0,0,1,1,0,0,0],\
....: [0,1,0,1,0,1,0,0],\
....: [1,1,0,1,0,0,1,1]])
sage: C = LinearCode(G)
sage: E = LCSE(C)
sage: E.generator_matrix()
Expand Down Expand Up @@ -1207,9 +1207,9 @@ def generator_matrix(self):

sage: LCSE = codes.encoders.LinearCodeSystematicEncoder
sage: G = Matrix(GF(2), [[1,1,1,0,0,0,0],\
[1,0,0,1,1,0,0],\
[0,1,0,1,0,1,0],\
[1,1,0,1,0,0,1]])
....: [1,0,0,1,1,0,0],\
....: [0,1,0,1,0,1,0],\
....: [1,1,0,1,0,0,1]])
sage: C = LinearCode(G)
sage: E = LCSE(C)
sage: E.generator_matrix()
Expand All @@ -1230,9 +1230,9 @@ def generator_matrix(self):
Another example where there is no generator matrix of the form `[I \vert H]`::

sage: G = Matrix(GF(2), [[1,1,0,0,1,0,1],\
[1,1,0,0,1,0,0],\
[0,0,1,0,0,1,0],\
[0,0,1,0,1,0,1]])
....: [1,1,0,0,1,0,0],\
....: [0,0,1,0,0,1,0],\
....: [0,0,1,0,1,0,1]])
sage: C = LinearCode(G)
sage: E = LCSE(C)
sage: E.generator_matrix()
Expand Down Expand Up @@ -1277,8 +1277,8 @@ def systematic_permutation(self):
EXAMPLES::

sage: C = LinearCode(matrix(GF(2), [[1,0,0,0,1,1,0],\
[0,1,0,1,0,1,0],\
[0,0,0,0,0,0,1]]))
....: [0,1,0,1,0,1,0],\
....: [0,0,0,0,0,0,1]]))
sage: E = codes.encoders.LinearCodeSystematicEncoder(C)
sage: E.systematic_positions()
(0, 1, 6)
Expand Down Expand Up @@ -1309,9 +1309,9 @@ def systematic_positions(self):

sage: LCSE = codes.encoders.LinearCodeSystematicEncoder
sage: G = Matrix(GF(2), [[1,1,1,0,0,0,0],\
[1,0,0,1,1,0,0],\
[0,1,0,1,0,1,0],\
[1,1,0,1,0,0,1]])
....: [1,0,0,1,1,0,0],\
....: [0,1,0,1,0,1,0],\
....: [1,1,0,1,0,0,1]])
sage: C = LinearCode(G)
sage: E = LCSE(C)
sage: E.systematic_positions()
Expand All @@ -1320,9 +1320,9 @@ def systematic_positions(self):
We take another matrix with a less nice shape::

sage: G = Matrix(GF(2), [[1,1,0,0,1,0,1],\
[1,1,0,0,1,0,0],\
[0,0,1,0,0,1,0],\
[0,0,1,0,1,0,1]])
....: [1,1,0,0,1,0,0],\
....: [0,0,1,0,0,1,0],\
....: [0,0,1,0,1,0,1]])
sage: C = LinearCode(G)
sage: E = LCSE(C)
sage: E.systematic_positions()
Expand All @@ -1343,8 +1343,8 @@ def systematic_positions(self):
positions (even if another choice might also be systematic)::

sage: G = Matrix(GF(2), [[1,0,0,0],\
[0,1,0,0],\
[0,0,1,1]])
....: [0,1,0,0],\
....: [0,0,1,1]])
sage: C = LinearCode(G)
sage: E = LCSE(C, systematic_positions=[0,1,3])
sage: E.systematic_positions()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/designs/gen_quadrangles_with_spread.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def generalised_quadrangle_hermitian_with_ovoid(const int q):
TESTS::

sage: from sage.combinat.designs.gen_quadrangles_with_spread import \
is_GQ_with_spread, dual_GQ_ovoid
....: is_GQ_with_spread, dual_GQ_ovoid
sage: t = designs.generalised_quadrangle_hermitian_with_ovoid(3)
sage: t = dual_GQ_ovoid(*t)
sage: is_GQ_with_spread(*t, s=3, t=9)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1821,8 +1821,8 @@ def parallel_dispatch(self):
canceled::

sage: from tempfile import NamedTemporaryFile as NTF
sage: with NTF(suffix='.py', mode='w+t') as f1, \
....: NTF(suffix='.py', mode='w+t') as f2:
sage: with (NTF(suffix='.py', mode='w+t') as f1,
....: NTF(suffix='.py', mode='w+t') as f2):
....: _ = f1.write("'''\nsage: import time; time.sleep(60)\n'''")
....: f1.flush()
....: _ = f2.write("'''\nsage: True\nFalse\n'''")
Expand Down
48 changes: 9 additions & 39 deletions src/sage/doctest/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,26 +880,6 @@ def parse(self, string, *args):
sage: ex.source
'for i in range(Integer(4)):\n print(i)\n'

Sage currently accepts backslashes as indicating that the end
of the current line should be joined to the next line. This
feature allows for breaking large integers over multiple lines
but is not standard for Python doctesting. It's not
guaranteed to persist::

sage: n = 1234\
....: 5678
sage: print(n)
12345678
sage: type(n)
<class 'sage.rings.integer.Integer'>

It also works without the line continuation::

sage: m = 8765\
4321
sage: print(m)
87654321

Optional tags at the start of an example block persist to the end of
the block (delimited by a blank line)::

Expand Down Expand Up @@ -993,15 +973,15 @@ def parse(self, string, *args):

sage: parse("::\n\n sage: # needs sage.combinat\n sage: from sage.geometry.polyhedron.combinatorial_polyhedron.conversions \\\n ....: import incidence_matrix_to_bit_rep_of_Vrep\n sage: P = polytopes.associahedron(['A',3])\n\n")
['::\n\n',
'',
(None,
'from sage.geometry.polyhedron.combinatorial_polyhedron.conversions import incidence_matrix_to_bit_rep_of_Vrep\n',
'from sage.geometry.polyhedron.combinatorial_polyhedron.conversions import incidence_matrix_to_bit_rep_of_Vrep\n'),
'',
(None,
"P = polytopes.associahedron(['A',3])\n",
"P = polytopes.associahedron(['A',Integer(3)])\n"),
'\n']
'',
(None,
'from sage.geometry.polyhedron.combinatorial_polyhedron.conversions \\\n import incidence_matrix_to_bit_rep_of_Vrep\n',
'from sage.geometry.polyhedron.combinatorial_polyhedron.conversions import incidence_matrix_to_bit_rep_of_Vrep\n'),
'',
(None,
"P = polytopes.associahedron(['A',3])\n",
"P = polytopes.associahedron(['A',Integer(3)])\n"),
'\n']

sage: example4 = '::\n\n sage: C.minimum_distance(algorithm="guava") # optional - guava\n ...\n 24\n\n'
sage: parsed4 = DTP.parse(example4)
Expand All @@ -1016,20 +996,10 @@ def parse(self, string, *args):
find_sage_continuation = re.compile(r"^(\s*)\.\.\.\.:", re.M)
find_python_continuation = re.compile(r"^(\s*)\.\.\.([^\.])", re.M)
python_prompt = re.compile(r"^(\s*)>>>", re.M)
backslash_replacer = re.compile(r"""(\s*)sage:(.*)\\\ *
\ *((\.){4}:)?\ *""")

# The following are used to allow ... at the beginning of output
ellipsis_tag = "<TEMP_ELLIPSIS_TAG>"

# Hack for non-standard backslash line escapes accepted by the current
# doctest system.
m = backslash_replacer.search(string)
while m is not None:
g = m.groups()
string = string[:m.start()] + g[0] + "sage:" + g[1] + string[m.end():]
m = backslash_replacer.search(string, m.start())

replace_ellipsis = not python_prompt.search(string)
if replace_ellipsis:
# There are no >>> prompts, so we can allow ... to begin the output
Expand Down
2 changes: 1 addition & 1 deletion src/sage/dynamics/arithmetic_dynamics/affine_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def dynatomic_polynomial(self, period):
sage: R.<c> = QQ[]
sage: Pc.<x,y> = ProjectiveSpace(R, 1)
sage: G = DynamicalSystem_projective([(1/2*c + 1/2)*x^2 + (-2*c)*x*y + 2*c*y^2 , \
(1/4*c + 1/2)*x^2 + (-c - 1)*x*y + (c + 1)*y^2])
....: (1/4*c + 1/2)*x^2 + (-c - 1)*x*y + (c + 1)*y^2])
sage: G.dehomogenize(1).dynatomic_polynomial(2)
(1/4*c + 1/4)*x^2 + (-c - 1/2)*x + c + 1
"""
Expand Down
8 changes: 4 additions & 4 deletions src/sage/dynamics/arithmetic_dynamics/projective_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2259,10 +2259,10 @@

::

sage: RSA768 = 123018668453011775513049495838496272077285356959533479219732245215\
....: 1726400507263657518745202199786469389956474942774063845925192557326303453731548\
....: 2685079170261221429134616704292143116022212404792747377940806653514195974598569\
....: 02143413
sage: RSA768 = Integer('123018668453011775513049495838496272077285356959533479219732245215'
....: '1726400507263657518745202199786469389956474942774063845925192557326303453731548'
....: '2685079170261221429134616704292143116022212404792747377940806653514195974598569'
....: '02143413')
sage: P.<x,y> = ProjectiveSpace(QQ,1)
sage: f = DynamicalSystem_projective([RSA768*x^2 + y^2, x*y])
sage: Q = P(RSA768,1)
Expand Down Expand Up @@ -6974,7 +6974,7 @@
sage: P.<x,y>=ProjectiveSpace(QQbar, 1)
sage: E=EllipticCurve([1, 2])
sage: f=P.Lattes_map(E, 2)
sage: f.Lattes_to_curve(check_lattes=true)

Check warning on line 6977 in src/sage/dynamics/arithmetic_dynamics/projective_ds.py

View workflow job for this annotation

GitHub Actions / test-new

Warning: slow doctest:

slow doctest:
Elliptic Curve defined by y^2 = x^3 + x + 2 over Rational Field

"""
Expand Down
Loading
Loading