[Python-ideas] PEP 563: Postponed Evaluation of Annotations, first draft

Steven D'Aprano steve at pearwood.info
Mon Sep 11 13:57:33 EDT 2017


On Mon, Sep 11, 2017 at 04:06:14PM +0000, אלעזר wrote:
> I like it. For previous discussion of this idea see here:
> https://mail.python.org/pipermail/python-ideas/2016-September/042527.html
> 
> I don't see this mentioned in the PEP, but it will also allow (easy)
> description of contracts and dependent types.

How?

You may be using a different meaning to the word "contract" than I'm 
familiar with. I'm thinking about Design By Contract, where the 
contracts are typically much more powerful than mere type checks, e.g. a 
contract might state that the argument is float between 0 and 1, or that 
the return result is datetime object in the future. There are (at 
least?) three types of contracts: preconditions, which specify the 
arguments, postconditions, which specify the return result, and 
invariants, which specify what doesn't change. 

I don't see how you can specify contracts in a single type annotation.


-- 
Steve


More information about the Python-ideas mailing list