dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #10873
Re: Strange error from function.py
On Tue, Dec 02, 2008 at 12:12:14PM +0100, Anders Logg wrote:
> I've tried adding a new class Constant in function.py:
>
> class Constant(ffc.Constant, dolfin.cpp_Function):
>
> def __init__(self, domain, value):
> "Create constant-valued function."
> print domain
> print value
> #ffc.Constant.__init__(self, domain)
> #dolfin.cpp_Constant.__init__(self, value)
>
> But I get the following error message:
>
> File
> "/scratch/fenics/dolfin/dolfin-dev/local/lib/python2.5/site-packages/dolfin/function.py", line 411, in <module>
> class Constant(ffc.Constant, dolfin.cpp_Function):
> TypeError: Error when calling the metaclass bases
> function() argument 1 must be code, not str
>
> How is this possible? There should be no metaclasses involved here
> (except the built-in Python metaclass type that is always there).
I get this error even if I just try to create a class named anything
that inherits from ffc.Constant.
Does the metaclass construction in function.py have side-effects?
I don't remember if we discussed this before, but would it be possible
(at least simpler) to instead define a simple Python function that
returns a "function" instance:
class FooFunction(ffc.Function, ...):
...
class BarFunction(dolfin.Function, ...):
...
def Function(V, *arg):
if foo:
return FooFunction(...)
elif bar:
return BarFunction(...)
This seems to be an easier solution. It would still be dynamic.
The only drawback would be that we can't do
isinstace(v, Function)
This can be solved by creating an empty class FunctionBase that all
the special types inherit from.
--
Anders
Attachment:
signature.asc
Description: Digital signature
Follow ups
References