-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
Sage doctest framework ignores amendments by decorators #34828
Comments
comment:2
cc'ing the authors of Sage's doctest framework |
This comment has been minimized.
This comment has been minimized.
comment:4
I would phrase this as an enhancement, not a defect. Sage's doctesting works by, as you say, scraping code from files, and you're asking that it instead read Maybe William can fill in some of the history. I wonder if in Sage's early days, Python's doctesting framework was underdeveloped, or maybe even nonexistent, so Sage created its own? By the time David Roe updated the framework, he used some of Python's |
comment:6
Sage's doctesting framework creates the tests by reading the file and searching for triple quoted strings; it does not actually execute python code. So I don't think there's an easy fix for this issue. Here's the function that actually creates the doctests: https://github.com/sagemath/sagetrac-mirror/blob/develop/src/sage/doctest/sources.py#n230 |
comment:7
Replying to David Roe:
The only reason for this I can imagine is wanting one tool for Python and Cython. For Cython - I actually don't know why one can't run a preprocessor of your choice on Cython, before doctesting... |
comment:8
I'm not saying it's not possible to change how the tests are created. But that's not currently how we interact with Python's doctest module. |
comment:9
I'm not going to be able to look at this much anytime soon (giving a talk in mid January that I still have a TON of work to do for, and then multiple trips after that). I think if I was trying to add this capability to Sage's doctest framework, I would try to create a new subclass of |
comment:10
Replying to Matthias Köppe:
I tried On the other hand, if on the git branch
4 is the total number of classes there, 2 with decorater-generated docstrings, and 2 with "normal" ones. Note that |
comment:11
Opened #34829 to address the out of tree oddity noted in comment:10 |
In vanilla Python it's prefectly possible to generate docstrings of a class or a function with a decorator, they will be doctested just fine.
However, in Sage it's not so - such amendments are ignored. Example:
running
sage -t c.py
on the following fileresults in
If we modify
c.py
to correct prompts in doctests to vanilla Python,and doctest:
we see that the doctest added by the decorator gets run (it fails by design, that's OK).
As we often have a lot of repeated boilerplate in docstrings, we're doing too much copy-paste, intstead of using decorators (it appears to be a common belief that doctest frameworks scrape code from files - it's not true, they operate on
__doc__
attributes, as we see).So something should be fixed in Sage doctest framework here.
CC: @mkoeppe @roed314 @robertwb @williamstein
Component: doctest framework
Issue created by migration from https://trac.sagemath.org/ticket/34828
The text was updated successfully, but these errors were encountered: