Opened 4 years ago

Last modified 3 years ago

#19088 new defect

multi-line doctests fail when using angle notation (preparser)

Reported by: dkrenn Owned by:
Priority: major Milestone: sage-6.9
Component: misc Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

The following fails

        sage: A.<n> = AsymptoticRing(growth_group='QQ^x * x^QQ * log(n)^QQ',
        ....:                         coefficient_ring=QQ); A

(used with the code of #17601, but is nothing specific about this code).

One gets:

    A.<n> = AsymptoticRing(growth_group='QQ^x * x^QQ * log(n)^QQ',
                           coefficient_ring=QQ); A
Exception raised:
    Traceback (most recent call last):
    ...
        A = AsymptoticRing(growth_group='QQ^x * x^QQ * log(n)^QQ',; (n,) = A._first_ngens(1)
                                                                  ^
    SyntaxError: invalid syntax

Change History (2)

comment:1 Changed 4 years ago by nbruin

Perhaps a simpler example: compare

sage: preparse("""A.<a,b,c>=PolynomialRing(QQ)""")
"A = PolynomialRing(QQ, names=('a', 'b', 'c',)); (a, b, c,) = A._first_ngens(3)"
sage: preparse("""A.<a,b,c>=PolynomialRing(QQ\n)""")
'A = PolynomialRing(QQ; (a, b, c,) = A._first_ngens(3)\n)'
sage: preparse("A.<x>=QQ[]")
"A = QQ['x']; (x,) = A._first_ngens(1)"
sage: preparse("A.<x>=QQ[\n]")
'A = QQ[; (x,) = A._first_ngens(1)\n]'

As you can see, the newline completely throws off the substitution:

  • no "names" attribute is inserted
  • the binding of generators to given identifiers is inserted in the wrong spot (at the end of the first line instead of at the end of the command)

This is a tricky one: Usually in python, a newline terminates a command, so the place of insertion would usually be safe. However, if there is an unbalanced bracket, then the newline is just a whitespace. This is a condition that cannot be detected with a regex in general.

comment:2 Changed 3 years ago by jdemeyer

  • Component changed from doctest framework to misc
Note: See TracTickets for help on using tickets.