Closed ChrisBeaumont closed 9 years ago
Hi Chris, I'll be traveling for the next few days. I'll answer when I get back towards the end of the week. A.
On Mon, Nov 17, 2014 at 3:42 PM, Chris Beaumont notifications@github.com wrote:
Hi @AndreaCensi https://github.com/AndreaCensi
Some more experimentation on my end: this change would allow you to pass args/kwargs into custom contracts:
@new_contractdef greater_than(value, thresh): return value > thresh
parse('greater_than(3)').check(4) parse('greater_than(3)').fail(3)
This provides a way for users to implement missing/undocumented features like #23 https://github.com/AndreaCensi/contracts/issues/23, and would also address the issue I raised in #26 https://github.com/AndreaCensi/contracts/issues/26
@new_contractdef t(value, typ): return isinstance(value, typ)
parse('t($Foo)')
Thoughts?
You can merge this Pull Request by running
git pull https://github.com/ChrisBeaumont/contracts multiarg
Or view, comment on, or merge it at:
https://github.com/AndreaCensi/contracts/pull/28 Commit Summary
- Allow args/kwargs to be passed to Extension contracts
File Changes
- M src/contracts/library/extensions.py https://github.com/AndreaCensi/contracts/pull/28/files#diff-0 (62)
- M src/contracts/main.py https://github.com/AndreaCensi/contracts/pull/28/files#diff-1 (48)
- M src/contracts/testing/test_new_contract.py https://github.com/AndreaCensi/contracts/pull/28/files#diff-2 (38)
Patch Links:
- https://github.com/AndreaCensi/contracts/pull/28.patch
- https://github.com/AndreaCensi/contracts/pull/28.diff
— Reply to this email directly or view it on GitHub https://github.com/AndreaCensi/contracts/pull/28.
Andrea Censi | LIDS / MIT | http://censi.mit.edu
Anyway it looks like a good idea.
On Mon, Nov 17, 2014 at 8:57 PM, Andrea Censi censi@mit.edu wrote:
Hi Chris, I'll be traveling for the next few days. I'll answer when I get back towards the end of the week. A.
On Mon, Nov 17, 2014 at 3:42 PM, Chris Beaumont notifications@github.com wrote:
Hi @AndreaCensi https://github.com/AndreaCensi
Some more experimentation on my end: this change would allow you to pass args/kwargs into custom contracts:
@new_contractdef greater_than(value, thresh): return value > thresh
parse('greater_than(3)').check(4) parse('greater_than(3)').fail(3)
This provides a way for users to implement missing/undocumented features like #23 https://github.com/AndreaCensi/contracts/issues/23, and would also address the issue I raised in #26 https://github.com/AndreaCensi/contracts/issues/26
@new_contractdef t(value, typ): return isinstance(value, typ)
parse('t($Foo)')
Thoughts?
You can merge this Pull Request by running
git pull https://github.com/ChrisBeaumont/contracts multiarg
Or view, comment on, or merge it at:
https://github.com/AndreaCensi/contracts/pull/28 Commit Summary
- Allow args/kwargs to be passed to Extension contracts
File Changes
- M src/contracts/library/extensions.py https://github.com/AndreaCensi/contracts/pull/28/files#diff-0 (62)
- M src/contracts/main.py https://github.com/AndreaCensi/contracts/pull/28/files#diff-1 (48)
- M src/contracts/testing/test_new_contract.py https://github.com/AndreaCensi/contracts/pull/28/files#diff-2 (38)
Patch Links:
- https://github.com/AndreaCensi/contracts/pull/28.patch
- https://github.com/AndreaCensi/contracts/pull/28.diff
— Reply to this email directly or view it on GitHub https://github.com/AndreaCensi/contracts/pull/28.
Andrea Censi | LIDS / MIT | http://censi.mit.edu
Andrea Censi | LIDS / MIT | http://censi.mit.edu
@AndreaCensi the __str__
doesn't properly embed args or kwargs yet:
In [1]: from contracts import new_contract, parse
In [2]: @new_contract
def foo(value, x, y, z):
pass
...:
In [3]: c = parse('foo(1,2,3)')
In [4]: c #ok
Out[4]: Extension('foo', args=(SimpleRValue(1), SimpleRValue(2), SimpleRValue(3)), kwargs={})
In [5]: print c # incomplete
foo
I think I can fix this easily, but were the unit tests supposed to catch it?
I think I can fix this easily, but were the unit tests supposed to catch it?
Yes they should have --- every contract is pickled, unpickled, compared with its serialization, rewritten, reparsed, etc.
Uhmmm....
On Fri, Nov 21, 2014 at 11:01 AM, Chris Beaumont notifications@github.com wrote:
@AndreaCensi https://github.com/AndreaCensi the str doesn't properly embed args or kwargs yet:
In [1]: from contracts import new_contract, parse
In [2]: @new_contract def foo(value, x, y, z): pass ...:
In [3]: c = parse('foo(1,2,3)')
In [4]: c #ok Out[4]: Extension('foo', args=(SimpleRValue(1), SimpleRValue(2), SimpleRValue(3)), kwargs={})
In [5]: print c # incomplete foo
I think I can fix this easily, but were the unit tests supposed to catch it?
— Reply to this email directly or view it on GitHub https://github.com/AndreaCensi/contracts/pull/28#issuecomment-63991082.
Andrea Censi | LIDS / MIT | http://censi.mit.edu
Well actually we didn't put any test about this.
See good()
, fail()
and syntax_fail()
use in many of the *_tc.py
files.
I'm writing some tests.
All right, we have some failures in the tests now. See src/contracts/testing/library/extensions_tc.py committed in master.
Just committed a fix to the tests. Now the only tests failing are showing the bug you found.
All tests running in master. Case closed.
Hi @AndreaCensi
Some more experimentation on my end: this change would allow you to pass args/kwargs into custom contracts:
This provides a way for users to implement missing/undocumented features like #23, and would also address the issue I raised in #26
Thoughts?