On Thursday, January 21, 2021 at 7:21:52 AM UTC-8 Nikos Apostolakis wrote: > Dear Vincent, > > Thank you very much, that fixes it. > > IMHO this is a bug though, or at least an inconsistent behavior. Most of > the time Sage silently coerces things to the appropriate type so commands > just work. For example: >
> > sage: m = 11 >> sage: l = (m-1)/2 -1 >> > sage: l >> 4 >> sage: range(5)[l] >> 4 > > > There's a subtle difference here: The python interface here requires an index to be something that can be converted into an integer; i.e., something for which the __int__ method does the right thing. "Coercion" in sage has a more restricted notion; see the docs. In sage, there is no coercion from QQ to ZZ, because there is no natural map from one to the other. There is a conversion, though, which is allowed to be a partial map. Generally, coercion maps only exist in one direction. Otherwise, things like ZZ(1)+QQ(2) whould have an ill-determined type. Whether "Words" should attempt to convert its second argument to an integer is a different matter. Generally it is best to start interface design by doing only a minimal amount of processing to the argument, because being "smart" for one thing can easily hide errors in another case. The error message that is currently given is perhaps a little generic, but it does clearly indicate that the arguments given to "Words" are problematic. Once you check that the *apparent* arguments work fine if entered directly, it's clear there's probably a type issue. If you use IPython's interactive debugger ("%debug") you can dive into the problematic code and query the arguments and their types directly, within the context where the error was raised. That can be a big time saver, because it can help you find the error without having to construct a stand-alone reproducible test case that you would need if you want to communicate the error to other people. -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/01a9d1dc-c402-444e-81c8-e8aa86b2945an%40googlegroups.com.