Good! However I think we should try use cpp.error instead.
J On Nov 1, 2012 2:33 AM, <nore...@launchpad.net> wrote: > ------------------------------------------------------------ > revno: 7062 > committer: Martin Sandve Alnæs <marti...@simula.no> > branch nick: work > timestamp: Thu 2012-11-01 10:28:38 +0100 > message: > Change some raise statements to future proof constructor syntax instead > of tuple syntax. > modified: > site-packages/dolfin/functions/function.py > > > -- > lp:dolfin > https://code.launchpad.net/~dolfin-core/dolfin/trunk > > Your team DOLFIN Core Team is subscribed to branch lp:dolfin. > To unsubscribe from this branch go to > https://code.launchpad.net/~dolfin-core/dolfin/trunk/+edit-subscription > > === modified file 'site-packages/dolfin/functions/function.py' > --- site-packages/dolfin/functions/function.py 2011-11-16 18:59:02 +0000 > +++ site-packages/dolfin/functions/function.py 2012-11-01 09:28:38 +0000 > @@ -35,7 +35,7 @@ > class MetaNoEvalOverloading(type): > def __init__(mcs, name, bases, dictionary): > if "eval" in dictionary: > - raise TypeError, "cannot overload 'eval'" > + raise TypeError("cannot overload 'eval'") > > class Function(ufl.Coefficient, cpp.Function): > """ > @@ -100,10 +100,10 @@ > """Initialize Function.""" > # Check arguments > if len(args) == 0: > - raise TypeError, "expected 1 or more arguments" > + raise TypeError("expected 1 or more arguments") > > if not isinstance(args[0], (FunctionSpaceBase, Function)): > - raise TypeError, "expected a FunctionSpace or a Function as > argument 1" > + raise TypeError("expected a FunctionSpace or a Function as > argument 1") > > # If using the copy constuctor > if isinstance(args[0], Function): > @@ -121,14 +121,14 @@ > num_sub_spaces = other.function_space().num_sub_spaces() > > if num_sub_spaces == 1: > - raise RuntimeError, "No subfunctions to extract" > + raise RuntimeError("No subfunctions to extract") > if not i < num_sub_spaces: > - raise RuntimeError, "Can only extract subfunctions > with i = 0..%d"% num_sub_spaces > + raise RuntimeError("Can only extract subfunctions > with i = 0..%d"% num_sub_spaces) > cpp.Function.__init__(self, other, i) > ufl.Coefficient.__init__(self, > self.function_space().ufl_element()) > return > else: > - raise TypeError, "expected one or two arguments when > instantiating from another Function" > + raise TypeError("expected one or two arguments when > instantiating from another Function") > > V = args[0] > > @@ -145,13 +145,13 @@ > # using the passed Function > if isinstance(args[1], cpp.Function): > if args[1].function_space().dim() != V.dim(): > - raise ValueError, "non matching dimensions on passed > FunctionSpaces" > + raise ValueError("non matching dimensions on passed > FunctionSpaces") > > cpp.Function.__init__(self, args[1]) > else: > cpp.Function.__init__(self, *args) > else: > - raise TypeError, "too many arguments" > + raise TypeError("too many arguments") > > def _sub(self, i, deepcopy = False): > """Return a sub function. > @@ -165,12 +165,12 @@ > > """ > if not isinstance(i, int): > - raise TypeError, "expects an 'int' as first argument" > + raise TypeError("expects an 'int' as first argument") > num_sub_spaces = self.function_space().num_sub_spaces() > if num_sub_spaces == 1: > - raise RuntimeError, "No subfunctions to extract" > + raise RuntimeError("No subfunctions to extract") > if not i < num_sub_spaces: > - raise RuntimeError, "Can only extract subfunctions with i = > 0..%d"% num_sub_spaces > + raise RuntimeError("Can only extract subfunctions with i = > 0..%d"% num_sub_spaces) > > # Create and instantiate the Function > if deepcopy: > @@ -197,7 +197,7 @@ > > num_sub_spaces = self.function_space().num_sub_spaces() > if num_sub_spaces == 1: > - raise RuntimeError, "No subfunctions to extract" > + raise RuntimeError("No subfunctions to extract") > return tuple(self._sub(i, deepcopy) for i in > xrange(num_sub_spaces)) > > def ufl_element(self): > @@ -295,7 +295,7 @@ > """ > > if len(args)==0: > - raise TypeError, "expected at least 1 argument" > + raise TypeError("expected at least 1 argument") > > # Test for ufl restriction > if len(args) == 1 and args[0] in ('+','-'): > @@ -312,11 +312,11 @@ > values = kwargs.get("values", None) > if values is not None: > if not isinstance(values, numpy.ndarray): > - raise TypeError, "expected a NumPy array for 'values'" > + raise TypeError("expected a NumPy array for 'values'") > if len(values) != value_size or \ > not numpy.issubdtype(values.dtype, 'd'): > - raise TypeError, "expected a double NumPy array of > length"\ > - " %d for return values."%value_size > + raise TypeError("expected a double NumPy array of length"\ > + " %d for return values."%value_size) > values_provided = True > else: > values_provided = False > @@ -339,14 +339,14 @@ > try: > x = numpy.fromiter(x, 'd') > except (TypeError, ValueError, AssertionError): > - raise TypeError, "expected scalar arguments for the > coordinates" > + raise TypeError("expected scalar arguments for the > coordinates") > > if len(x) == 0: > - raise TypeError, "coordinate argument too short" > + raise TypeError("coordinate argument too short") > > if len(x) != dim: > - raise TypeError, "expected the geometry argument to be of "\ > - "length %d"%dim > + raise TypeError("expected the geometry argument to be of "\ > + "length %d"%dim) > > # The actual evaluation > self.eval(values, x) > @@ -365,7 +365,7 @@ > """ > def __init__(self, V, index=None): > if not isinstance(V, FunctionSpaceBase): > - raise TypeError, "Illegal argument for creation of Argument, > not a FunctionSpace: " + str(V) > + raise TypeError("Illegal argument for creation of Argument, > not a FunctionSpace: " + str(V)) > ufl.Argument.__init__(self, V.ufl_element(), index) > self._V = V > > > >
_______________________________________________ Mailing list: https://launchpad.net/~dolfin Post to : dolfin@lists.launchpad.net Unsubscribe : https://launchpad.net/~dolfin More help : https://help.launchpad.net/ListHelp