예제 #1
0
파일: exceptions.py 프로젝트: xwang862/psi4
def exact_arg_count(num, given):
    """ Shorthand for raising a TypeError telling the user that more than the maximum number of arguments was given.
    Uses the standard python form of the expression.
    """
    return TypeError(caller() + "() takes exactly " + str(num)
                     + " argument" + ("" if num == 1 else "s")
                     + "(" + str(given) + " given)")
예제 #2
0
파일: exceptions.py 프로젝트: xwang862/psi4
def min_arg_count(min, given):
    """ Shorthand for raising a TypeError telling the user that fewer than the minimum number of arguments was given.
    Uses the standard python form of the expression.
    """
    return TypeError(caller() + "() takes at least " + str(min)
                     + " argument" + ("" if min == 1 else "s")
                     + "(" + str(given) + " given)")
예제 #3
0
파일: exceptions.py 프로젝트: xwang862/psi4
 def __init__(self, keyword1, keyword2, func=None):
     if caller is None:
         callfunc = caller()
     else:
         callfunc = func
     message = ("Function {0}() called with conflicting keyword arguments:"
                "  It can be called with the keyword {1} or {2}, but not both.").format(callfunc, keyword1, keyword2)
     super(ConflictingKwargs, self).__init__(message)
예제 #4
0
파일: exceptions.py 프로젝트: xwang862/psi4
 def __new__(cls, argname, arg, *allowed_types, **kwargs):
     allowed = listify_args(allowed_types)
     my_caller = get_kwarg(kwargs, 'caller') or (caller() + '()')
     if len(allowed) == 1:
         return TypeError('Argument {0} to {1} must be {2} (got {3})'.format(
             argname,
             my_caller,
             classname(allowed[0]),
             type(arg).__name__
         ))
     else:
         return TypeError("Argument {0} to {1} must be one of ({2}) (got {3})".format(
             argname,
             my_caller,
             ', '.join(classname(a) for a in allowed),
             type(arg).__name__
         ))
예제 #5
0
 def fail_if_frozen(self):
     if self.frozen:
         raise FrozenObjectError(
             "Can't call method {0}() on instance {1} of {2} once "
             "it has been frozen.".format(caller(), self, classname(self)))
예제 #6
0
 def fail_if_frozen(self):
     if self.frozen:
         raise FrozenObjectError("Can't call method {0}() on instance {1} of {2} once "
                                             "it has been frozen.".format(caller(), self, classname(self)))