Opened 9 years ago

Last modified 5 years ago

#12920 needs_work enhancement

Decorators for sharing code between is_bar and _test_bar methods. — at Version 2

Reported by: nthiery Owned by: mvngu
Priority: major Milestone: sage-7.6
Component: misc Keywords: days38
Cc: sage-combinat Merged in:
Authors: Nicolas M. Thiéry Reviewers: Franco Saliola
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by nthiery)

{{{is_method}} / {{{_test_from_is_method}}: method wrappers to factor out code between {{{is_bar}} and {{{_test_bar}} methods

From the documentation:

The typical usecase for those wrappers is as follow: Consider a category {{{Foo}} with a subcategory {{{Bar}}. {{{Foo}} wants to provide a method {{{Foo.ParentMethods?.is_bar}} such that, for {{{F}} in {{{Foo()}}, {{{F.is_bar()}} returns whether {{{F}} satisfies all the properties of {{{Bar()}}. The method {{{is_bar}} is allowed to assume that {{{F}} indeed satisfies all the properties specified by {{{Foo()}}. It may decide to upgrade the category of {{{F}} to {{{Bar()}}.

{{{Bar}} itself wants to provide a method {{{Bar.ParentMethod?._test_bar}} which is supposed to do some reasonable sanity checks on {{{F}} to determine whether it satisfies all the properties of {{{Bar}}. If yes, {{{F._test_bla()}} should return None; otherwise it should raise some (hopefully meaningful) assertion. Note that {{{Bar()}} will typically override {{{is_bar}} by a trivial method that always returns {{{True}}.

The purpose of two decorators {{{is_method}} and {{{_test_method_from_is}} is to factor out the logic between the two related methods {{{F.is_bla()}} and {{{F._test_bla()}}. They take as input a Python function {{{is_bla(self, proof=False, options)}}. This function should proceed as usual for a {{{_test method}} (see :class:TestSuite). If {{{proof}} is {{{True}}, then the answer should be provably correct. At the end, {{{is_bla}} should return {{{None}}, or a category that will be used to refine the category of {{{F}}.

Change History (2)

comment:1 Changed 9 years ago by nthiery

  • Description modified (diff)
  • Status changed from new to needs_review

comment:2 Changed 9 years ago by nthiery

  • Description modified (diff)
Note: See TracTickets for help on using tickets.