Skip to content

Commit 26d6766

Browse files
author
Matthias Koeppe
committed
src/doc/en/developer/doctesting.rst: Explain prompt engineering for the doctest fixer
1 parent 37d2303 commit 26d6766

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/doc/en/developer/doctesting.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,54 @@ is automatically transformed to::
15471547
The doctest fixer also aligns the ``# optional/needs FEATURE`` tags on
15481548
individual doctests at a fixed set of tab stops.
15491549

1550+
The doctester may issue style warnings when ``# optional/needs`` tags are
1551+
repeated on a whole block of doctests, suggesting to use a block-scoped tag
1552+
instead. The doctest fixer makes these changes automatically.
1553+
1554+
There are situations in which the doctester and doctest fixer show too
1555+
much restraint and a manual intervention would improve the formatting
1556+
of the doctests. In the example below, the doctester does not issue a
1557+
style warning because the first doctest line does not carry the ``# needs``
1558+
tag::
1559+
1560+
| EXAMPLES::
1561+
|
1562+
| sage: set_verbose(-1)
1563+
| sage: P.<x,y,z> = ProjectiveSpace(QQbar, 2) # needs sage.rings.number_field
1564+
| sage: C = Curve([x^3*y + 2*x^2*y^2 + x*y^3 # needs sage.rings.number_field
1565+
| ....: + x^3*z + 7*x^2*y*z
1566+
| ....: + 14*x*y^2*z + 9*y^3*z], P)
1567+
| sage: Q = P([0,0,1]) # needs sage.rings.number_field
1568+
| sage: C.tangents(Q) # needs sage.rings.number_field
1569+
| [x + 4.147899035704788?*y,
1570+
| x + (1.426050482147607? + 0.3689894074818041?*I)*y,
1571+
| x + (1.426050482147607? - 0.3689894074818041?*I)*y]
1572+
1573+
To change this example, there are two approaches:
1574+
1575+
#. Just add the line ``sage: # needs sage.rings.number_field`` at
1576+
the beginning and run the doctest fixer, which will remove the tags on the individual
1577+
doctests that have now become redundant.
1578+
1579+
#. Insert a blank line after the first doctest line, splitting the block into two.
1580+
Now the ``# needs`` tag is repeated on the whole second block, so running the doctest
1581+
fixer will add a block-scoped tag and remove the individual tags::
1582+
1583+
| EXAMPLES::
1584+
|
1585+
| sage: set_verbose(-1)
1586+
|
1587+
| sage: # needs sage.rings.number_field
1588+
| sage: P.<x,y,z> = ProjectiveSpace(QQbar, 2)
1589+
| sage: C = Curve([x^3*y + 2*x^2*y^2 + x*y^3
1590+
| ....: + x^3*z + 7*x^2*y*z
1591+
| ....: + 14*x*y^2*z + 9*y^3*z], P)
1592+
| sage: Q = P([0,0,1])
1593+
| sage: C.tangents(Q)
1594+
| [x + 4.147899035704788?*y,
1595+
| x + (1.426050482147607? + 0.3689894074818041?*I)*y,
1596+
| x + (1.426050482147607? - 0.3689894074818041?*I)*y]
1597+
15501598
In places where the doctester issues a doctest dataflow warning
15511599
(``Variable ... referenced here was set only in doctest marked '# optional - FEATURE'``),
15521600
the doctest fixer automatically adds the missing ``# optional/needs`` tags.

0 commit comments

Comments
 (0)