New behavior:
Because the new behavior should not break any existing usage, this remains a “1.x” release.
No new features since 0.9.4, mainly performance improvements and some bug fixes.
Main changes:
Bug fixes:
Performance improvements:
New experimental features:
Contracts for class methods (suggestion by William Furr). Documentation still to write; here’s an example:
from contracts import new_contract, contract
class Game(object):
def __init__(self, legal_moves):
self.legal_moves = legal_moves
# You can now create a contract from object methods
# that can use the object attributes to validate the value.
@new_contract
def legal_move(self, move):
if not move in self.legal_moves:
raise ValueError('Move not valid')
@contract(move='legal_move')
def take_turn(self, move):
pass
game = Game(legal_moves=[1,2,3])
game.take_turn(1) # ok
game.take_turn(5) # raises exception
New features:
Interface change: the decorator is now called contract instead of contracts, because from contracts import contracts looked quite clumsy (the old form is still available).
The @contract decorator now changes the function’s docstring to show the contracts for the parameters. See an example application.
Implemented the generic contracts seq and map that generalize list and dict when any Sequence or Mapping will do.
Added element-by-element tests in array. Now in an expression of the kind array(>=0|<-1) the expression will be evaluate element by element.
Implemented pi as a special constant that can be used in the contracts.
Now it is possible to give more context to calls to check and fail through the use of keywords variable. For example:
check('array[*xM]', a, M=2)
Added a function disable_all() that disables all testing done by PyContracts. This can be used to make sure that PyContracts is not slowing things down.
Various fixes:
(changelog not available)