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
399 stars 61 forks source link

Improved string support for Python 2.x #6

Closed Xion closed 12 years ago

Xion commented 12 years ago

I found that support for string contracts in Python 2.x is lacking because the string/str keyword matches only str type. For applications using Unicode strings, that's not really viable.

So I made some improvements in this regard:

I'm aware that the last change modifies the original meaning of string keyword for Python 2.x so that it's more lenient. Existing contract specs using string will still allow what they used to allow, of course, but they will now also accept unicode strings in addition to str ones. So it doesn't break existing usage while (I think) making the keyword more intuitive for Python 2.x developers.

Also, the current meaning of string is not really documented anywhere (I had to find it in source, personally) and thus I suppose changing it slightly will not harm any existing usage.

AndreaCensi commented 12 years ago

Hi Xion, great job!

I'll test it and then release a new version in a couple of days.

AndreaCensi commented 12 years ago

Just released version 1.4.0 including this patch.