Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ install:
- pip install .
- pip install -r requirements.txt

script: nosetests --with-coverage tests
script: nosetests --with-coverage --nologcapture tests

after_success:
coveralls
10 changes: 10 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ Python 2
.. automethod:: __init__


Pragma
======

.. autofunction:: miniutils.pragma.unroll

.. autofunction:: miniutils.pragma.collapse_literals

.. autofunction:: miniutils.pragma.deindex


Miscellaneous
=============

Expand Down
14 changes: 11 additions & 3 deletions miniutils/magic_contract.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from contracts import contract, new_contract
from contracts import *
from contracts.library import Extension as _Ext
from miniutils.opt_decorator import optional_argument_decorator


# TODO: Figure out efficient mechanism to only enable contracts during testing or debug modes


def safe_new_contract(name, *args, **kwargs):
if name not in _Ext.registrar:
new_contract(name, *args, **kwargs)


@optional_argument_decorator
def magic_contract(*args, **kwargs):
"""Drop-in replacement for ``pycontracts.contract`` decorator, except that it supports locally-visible types
Expand All @@ -13,8 +21,8 @@ def magic_contract(*args, **kwargs):
"""
def inner_decorator(f):
for name, val in f.__globals__.items():
if not name.startswith('_') and name not in _Ext.registrar and isinstance(val, type):
new_contract(name, val)
if not name.startswith('_') and isinstance(val, type):
safe_new_contract(name, val)
return contract(*args, **kwargs)(f)

return inner_decorator
Loading