Dmitry Viskov
Сastle-builder, traveler, heavy music lover, cyclist, designer of web-systems, linux fan
Dmitry Viskov
dmitry.viskov@webenterprise.ru
def fib(n: int) -> None:
a, b = 0, 1
while a < n:
print(a)
a, b = b, a+b
def foo(a: 'x', b: 5 + 6, c: list) -> max(2, 9):
...
def bar(t: int) -> None:
print(t)
return True
print(bar('test')) # it works!
Find bugs of course!
from typing import List
a = [] # type: List[str]
a.append(0)
a.append("i")
print(a) # [0, 'i']
$ python test3.py
[0, 'i']
$ mypy test3.py
test3.py:5: error: Argument 1 to "append" of "list" has
incompatible type "int"; expected "str"
from typing import List, Any
a = [] # type: List[Any]
a.append(0)
a.append("i")
print(a) # [0, 'i']
$ mypy --py2 program.py
from contracts import contract
@contract(a='int,>0', b='list[N],N>0', returns='list[N]')
def my_function(a, b):
return [1,2,3]
print my_function(1, [])
File "/srv/venvs/annotations/local/lib/python2.7/site-packages/contracts/main.py", line 253, in contracts_checker
raise e
contracts.interface.ContractNotRespected: Breach for argument 'b' to my_function().
Condition 0 > 0 not respected
checking: N>0 for value: Instance of <type 'list'>: []
checking: list[N],N>0 for value: Instance of <type 'list'>: []
Variables bound in inner context:
- N: Instance of <type 'int'>: 0
from contracts import contract, new_contract
@new_contract
def my_condition(x):
return x > 0
@contract
def fun(a):
"""
Description...
:type a: ``list(my_condition)``
"""
pass
fun([1,0])
dmitry.viskov@webenterprise.ru
strannik_nnov
By Dmitry Viskov
Сastle-builder, traveler, heavy music lover, cyclist, designer of web-systems, linux fan