AndreaCensi / contracts

PyContracts is a Python package that allows to declare constraints on function parameters and return values. Contracts can be specified using Python3 annotations, or inside a docstring. PyContracts supports a basic type system, variables binding, arithmetic constraints, and has several specialized contracts and an extension API.
http://andreacensi.github.io/contracts/
Other
398 stars 62 forks source link

attr() doesn't seem to work with attributes that have an underscore in their name. #99

Open jesnie opened 2 years ago

jesnie commented 2 years ago

attr() doesn't seem to work with attributes that have an underscore in their name.

For example:

from contracts import contract

class A:
    b = 3
    b_2 = 4

@contract(a="attr(b:int)")  # Works.
def foo(a: A) -> None:
    pass

foo(A())

@contract(a="attr(b_2:int)")  # AssertionError: Bug in syntax
def foo2(a: A) -> None:
    pass

foo2(A())