Make multimethods work with inheritance. (#3411)

Previously, this would fail with a NoSuchMethodError:

    class Package(object):
        # this is the default implementation
        def some_method(self):
            ...

    class Foo(Package):
        @when('platform=cray')
        def some_method(self):
            ...

        @when('platform=linux')
        def some_method(self):
            ...

This fixes the implementation of `@when` so that the superclass method
will be invoked when no subclass method matches.

Adds tests to ensure this works, as well.
This commit is contained in:
Todd Gamblin
2017-03-11 05:48:36 -08:00
committed by GitHub
parent 15f80ed15c
commit e3101808ae
4 changed files with 68 additions and 4 deletions

View File

@@ -25,8 +25,10 @@
from spack import *
import spack.architecture
from spack.pkg.builtin.mock.multimethod_base import MultimethodBase
class Multimethod(Package):
class Multimethod(MultimethodBase):
"""This package is designed for use with Spack's multimethod test.
It has a bunch of test cases for the @when decorator that the
test uses.
@@ -132,3 +134,11 @@ def different_by_virtual_dep(self):
@when('^mpi@2:')
def different_by_virtual_dep(self):
return 2
#
# Make sure methods with a default implementation in a superclass
# will invoke that method when none in the subclass match.
#
@when("@2:")
def base_method(self):
return "subclass_method"