Hi Simon, > This post has two purposes: An advertisement for trac ticket #11342, > and a technical question about a trick used in that ticket. > > First, the question. > > Usually, an error is raised with an error message. And thus, the cdef > function sage.structure.parent.raise_attribute_error(P,name) first > creates a nice message stating that P does not have the attribute of > the given name. > > But the typical fate of an attribute error is being caught. Hence, > normally, nobody will ever see the error message, and it is a waste of > time to create it in the first place.
I had a very similar problem with the test suite error messages which sometimg slowed sown the suite but several order of magnitude. I solved this issue in #8742 by creating a class for lazy format string. I'm not sure this will solve your problem but if it does, maybe it is not a good idea to duplicate a feature. > One of the tricks that I use in #11342 to generally speed up getattr > of parents and elements is to introduce a new class > AttributeErrorMessage. It simply stores the class of P and the given > attribute name. Its string representation is the error message, and it > will *only* be created when requested (hence, not during > initialisation and not if the error is simply caught). In my usecases, I had some error message containing some " %s "%(bla) where the conversion from bla to its string representation take some time. So my idea was to create a class LazyFormat inheriting from str to create an object sur that the % operator is only evaluated when __repr__ is called. I still create the instance of LazyFormat which take a little time. I'm not sure how this fits your usecase. Cheers, Florent -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org