Commits

Kamil Kisiel committed 7d6922c

Renamed py3k -> annotations

  • Participants
  • Parent commits 1f9f788

Comments (0)

Files changed (3)

File covenant/__init__.py

 from covenant.invariant import *
 
 if sys.version_info >= (3, 0):
-    from covenant.py3k import *
+    from covenant.annotations import *

File covenant/annotations.py

+from inspect import getcallargs
+from functools import wraps
+
+from covenant.util import toggled_decorator
+from covenant.exceptions import (PreconditionViolationError,
+                                 PostconditionViolationError)
+
+
+@toggled_decorator
+def constrain(func):
+    @wraps(func)
+    def wrapped_func(*args, **kwargs):
+        callargs = getcallargs(func, *args, **kwargs)
+        for arg, arg_value in callargs.items():
+            if arg in func.__annotations__:
+                result = func.__annotations__[arg](arg_value)
+                if not result:
+                    raise PreconditionViolationError(
+                        "Precondition check failed: {0}".format(arg_value))
+
+        value = func(*args, **kwargs)
+
+        if "return" in func.__annotations__:
+            result = func.__annotations__["return"](value)
+            if not result:
+                raise PostconditionViolationError(
+                    "Postcondtion check failed: {0}" .format(value))
+
+        return value
+
+    return wrapped_func

File covenant/py3k.py

-from inspect import getcallargs
-from functools import wraps
-
-from covenant.util import toggled_decorator
-from covenant.exceptions import (PreconditionViolationError,
-                                 PostconditionViolationError)
-
-
-@toggled_decorator
-def constrain(func):
-    @wraps(func)
-    def wrapped_func(*args, **kwargs):
-        callargs = getcallargs(func, *args, **kwargs)
-        for arg, arg_value in callargs.items():
-            if arg in func.__annotations__:
-                result = func.__annotations__[arg](arg_value)
-                if not result:
-                    raise PreconditionViolationError(
-                        "Precondition check failed: {0}".format(arg_value))
-
-        value = func(*args, **kwargs)
-
-        if "return" in func.__annotations__:
-            result = func.__annotations__["return"](value)
-            if not result:
-                raise PostconditionViolationError(
-                    "Postcondtion check failed: {0}" .format(value))
-
-        return value
-
-    return wrapped_func