[Python-ideas] Why is design-by-contracts not widely adopted?

Chris Angelico rosuav at gmail.com
Wed Sep 26 15:36:10 EDT 2018

On Thu, Sep 27, 2018 at 5:07 AM Chris Barker <chris.barker at noaa.gov> wrote:
> On Tue, Sep 25, 2018 at 10:10 PM Lee Braiden <leebraid at gmail.com> wrote:
>> It's the reason why type checking exists, and why bounds checking exists, and why unit checking exists too.
> And yet Python has none of those. They all provide safety, but also place a burden on the developer.

Type checking? Depends on your definition. Since objects are typed,
Python is safe against the old "I passed an integer when it expected
an array" problem (which probably would result in a junk memory read,
in C), whether the function's arguments are type-checked or not. And
if you want actual type checking, that's available too, just not as
part of the core language (and it has language support for its

Bounds checking? Most definitely exists. If you try to subscript a
string or list with a value greater than its length, you get an

Unit checking? If that's "unit testing", that's part of the standard
library, so yes, that definitely exists in Python.


More information about the Python-ideas mailing list