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:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user