Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
scnerd committed Dec 5, 2017
2 parents 58c8789 + cc900b0 commit e36b366
Show file tree
Hide file tree
Showing 6 changed files with 350 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
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
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
@@ -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

0 comments on commit e36b366

Please sign in to comment.