On Saturday, October 19, 2019 at 1:20:15 PM UTC-7, David Roe wrote:
>
> I think the idea is that if a user's typing interactively then they don't 
> need a deprecation warning (since the behavior currently works).  It's more 
> important to show a user a warning if they have the deprecated behavior in 
> a function they've written.
>
 
I'm pretty sure that's not the reason. As you can see from 
https://trac.sagemath.org/ticket/28500, the stack depth is tuned so that 
the warning references the stack frame of the *call site* of the function 
raises the deprecation warning. That makes sense, because that's where the 
change should be made if you want to avoid calling a deprecated function. 
That works just fine from the interpreter top level, because there is a 
stack frame corresponding to top level.

The problem arises when the deprecation warning is raised in a cython 
function, since cython doesn't create python stack frames. With one less 
frame on the stack, the warning ends up referencing the level *above* the 
call site, which is there in the doctest framework, but not at top-level in 
the interpreter. In the doctest it means there's a nonsensical callsite 
referenced (but this is not checked by the doctests); in the interpreter it 
means the warning gets swallowed because a a failure in finding a stack 
frame [I think that behaviour is a bug in Python's warning machinery. It's 
a silent failure to issue a warning in a case where some warning is almost 
certainly desired].

The obvious solution is to use a different "deprecation" in cython code: 
one that uses a stack depth of one less. This is quite easy to implement by 
providing a "deprecation_cython" as well and use something like "from 
sage.misc.superseded import deprecation_cython as deprecation" in cython 
files instead of the usual. Making this change is quite straightforward (it 
can probably be done by a script if you really want to) and is completely 
uncontroversial. It is a bit of work, though, and it will be touching a lot 
of files.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/9f02b869-2528-436e-96c3-dcabe792d32b%40googlegroups.com.

Reply via email to