(f)
| 53 | precinfo.append((appargs, closureargs, p)) |
| 54 | |
| 55 | def decorate(f): |
| 56 | fspec = inspect.getfullargspec(f) |
| 57 | |
| 58 | for (appargs, closureargs, p) in precinfo: |
| 59 | for apparg in appargs: |
| 60 | if apparg not in fspec.args: |
| 61 | raise PreconditionError( |
| 62 | ( |
| 63 | "Invalid precondition refers to unknown parameter {!r}:\n" |
| 64 | + " {!s}\n" |
| 65 | + "Known parameters: {!r}\n" |
| 66 | ).format(apparg, stripped_source(p), fspec.args) |
| 67 | ) |
| 68 | for carg in closureargs: |
| 69 | if carg in fspec.args: |
| 70 | raise PreconditionError( |
| 71 | ( |
| 72 | "Invalid precondition masks parameter {!r}:\n" |
| 73 | + " {!s}\n" |
| 74 | + "Known parameters: {!r}\n" |
| 75 | ).format(carg, stripped_source(p), fspec.args) |
| 76 | ) |
| 77 | |
| 78 | @wraps(f) |
| 79 | def g(*a, **kw): |
| 80 | args = inspect.getcallargs(f, *a, **kw) |
| 81 | for (appargs, _, p) in precinfo: |
| 82 | if not p(*[args[aa] for aa in appargs]): |
| 83 | raise PreconditionError( |
| 84 | "Precondition failed in call {!r}{}:\n {!s}\n".format( |
| 85 | g, |
| 86 | inspect.formatargvalues( |
| 87 | fspec.args, fspec.varargs, fspec.varkw, args |
| 88 | ), |
| 89 | stripped_source(p), |
| 90 | ) |
| 91 | ) |
| 92 | |
| 93 | return f(*a, **kw) |
| 94 | |
| 95 | g.nopre = f |
| 96 | return g |
| 97 | |
| 98 | return decorate |
| 99 |
nothing calls this directly
no test coverage detected
searching dependent graphs…