Skip to content

Commit

Permalink
updated to icontract 1.7.1 (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
mristin committed Oct 21, 2018
1 parent f1f5d66 commit 287884f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions icontract_lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _find_condition_node(self, node: astroid.nodes.Call) -> Optional[astroid.nod

return condition_node

@icontract.pre(lambda pytype: pytype in ['icontract.pre', 'icontract.post'])
@icontract.pre(lambda pytype: pytype in ['icontract._decorators.pre', 'icontract._decorators.post'])
def _verify_precondition_or_postcondition_decorator(self, node: astroid.nodes.Call, pytype: str,
func_arg_set: Set[str], func_has_result: bool) -> None:
"""
Expand Down Expand Up @@ -238,10 +238,10 @@ def _verify_precondition_or_postcondition_decorator(self, node: astroid.nodes.Ca
condition_arg_set = set(condition.argnames())

# Verify
if pytype == 'icontract.pre':
if pytype == 'icontract._decorators.pre':
self._verify_pre(func_arg_set=func_arg_set, condition_arg_set=condition_arg_set, lineno=node.lineno)

elif pytype == 'icontract.post':
elif pytype == 'icontract._decorators.post':
self._verify_post(
func_arg_set=func_arg_set,
func_has_result=func_has_result,
Expand Down Expand Up @@ -321,16 +321,19 @@ def _check_func_decorator(self, node: astroid.nodes.Call, decorator: astroid.bas
pytype = decorator.pytype()

# Ignore non-icontract decorators
if pytype not in ["icontract.pre", "icontract.snapshot", "icontract.post"]:
if pytype not in ["icontract._decorators.pre", "icontract._decorators.snapshot", "icontract._decorators.post"]:
return

if pytype in ['icontract.pre', 'icontract.post']:
if pytype in ['icontract._decorators.pre', 'icontract._decorators.post']:
self._verify_precondition_or_postcondition_decorator(
node=node, pytype=pytype, func_arg_set=func_arg_set, func_has_result=func_has_result)

elif pytype == 'icontract.snapshot':
elif pytype == 'icontract._decorators.snapshot':
self._verify_snapshot_decorator(node=node, func_arg_set=func_arg_set)

else:
raise NotImplementedError("Unhandled pytype: {}".format(pytype))

def _infer_decorator(self, node: astroid.nodes.Call) -> Optional[astroid.bases.Instance]:
"""
Try to infer the decorator as instance of a class.
Expand Down Expand Up @@ -389,7 +392,7 @@ def visit_FunctionDef(self, node: astroid.nodes.FunctionDef) -> None: # pylint:
pytypes = [decorator.pytype() for decorator in decorators if decorator is not None] # type: List[str]
assert all(isinstance(pytype, str) for pytype in pytypes)

if 'icontract.snapshot' in pytypes and 'icontract.post' not in pytypes:
if 'icontract._decorators.snapshot' in pytypes and 'icontract._decorators.post' not in pytypes:
self.errors.append(
Error(
identifier=ErrorID.SNAPSHOT_WO_POST,
Expand Down Expand Up @@ -417,7 +420,7 @@ def _check_class_decorator(self, node: astroid.Call) -> None:

pytype = decorator.pytype()

if pytype != 'icontract.inv':
if pytype != 'icontract._decorators.inv':
return

condition_node = self._find_condition_node(node=node)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
license='License :: OSI Approved :: MIT License',
keywords='design-by-contract precondition postcondition validation lint',
packages=find_packages(exclude=['tests']),
install_requires=['icontract>=1.7.0,<2', 'astroid>=2.0.4,<3'],
install_requires=['icontract>=1.7.1,<2', 'astroid>=2.0.4,<3'],
extras_require={
'dev': [
# yapf: disable
Expand Down

0 comments on commit 287884f

Please sign in to comment.