Hi Jason, On 25 Okt., 22:48, Jason Grout <jason-s...@creativetrax.com> wrote: > I think attributes are considered more pythonic for many things than > methods.
That's good to know! So, I assume that it is OK that I suggest to replace C.all_super_categories() and C.super_categories() by lazy attributes. By the way, #11943 needs review :) > We insist on methods for many things in Sage because you can > document methods (but it's hard and not intrinsically supported by > python to document and introspect attribute documentation). I wonder: Could (and should) that be done using the preparser? That's to say: Assume that an input line ends with ? or ?? and is preceded by something like "Foo.Bar.bla". Would it be feasible that the preparser tests whether "Foo.Bar.__class__" has an attribute "bla"? If it has, the preparser could replace "Foo.Bar.bla?" by "Foo.Bar.__class__.bla?". I am not suggesting that such replacement should occur when function calls are involved: "Foo.Bar().bla?" should remain unchanged (currently, "Foo.Bar().bla?" results in an error anyway). This is to avoid costly function calls. The effect would be: If bla is a lazy attribute of Foo.Bar, then Foo.Bar.bla? would be the same as Foo.Bar.__class__.bla?, and would thus show the documentation of the lazy attribute, and not the documentation of the result of calling the lazy attribute. > This is from the PEP 8 style guide:http://www.python.org/dev/peps/pep-0008/ > > ... > Note 3: Avoid using properties for computationally expensive > operations; the attribute notation makes the caller believe > that access is (relatively) cheap. That's the case for super_categories and all_super_categories: They are cheap, the result is cached anyway, so, why not turn them into a "property" (is that essentially the same as a lazy attribute?)? Best regards, Simon -- 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