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

Chris Angelico rosuav at gmail.com
Fri Sep 28 20:32:16 EDT 2018

On Sat, Sep 29, 2018 at 10:22 AM Dan Sommers
<2QdxY4RzWzUUiLuE at potatochowder.com> wrote:
> On 9/28/18 7:39 PM, Steven D'Aprano wrote:
> > But none of that compares to C undefined behaviour. People who think
> > that they are equivalent, don't understand C undefined behaviour.
> Well, yes:  Some syntactically legal C results in nasal demons, and some
> of that code is harder to spot than others.  AFAIK, syntactically legal
> Python can only do that if the underlying C code invokes undefined
> behaviour.

What should happen here?

>>> import ctypes
>>> ctypes.cast(id(1), ctypes.POINTER(ctypes.c_int))[6] = 0
>>> 1

Nothing here invokes C's undefined behaviour. Or what about here:

>>> import sys; sys.setrecursionlimit(2147483647)
>>> def f(): f()
>>> f()

Python has its own set of "well don't do that then" situations. In
fact, I would say that *most* languages do.


More information about the Python-ideas mailing list