Missing exceptions in PEP 3107

Carl Banks pavlovevidence at gmail.com
Sun Aug 17 08:18:18 CEST 2008


On Aug 15, 3:42 pm, Christoph Zwerschke <c... at online.de> wrote:
> Carl Banks wrote:
>  > IOW, there is currently no recommended way to do *anything* with
>  > annotations(**).  That is entirely left up to users and third-party
>  > packages, and the PEP goes out of its way to disclaim all authority on
>  > policy.  The following quote from the PEP sums it up well:
>  >
>  > "Following from point 2, this PEP makes no attempt to introduce any
>  > kind of standard semantics, even for the built-in types. This work
>  > will be left to third-party libraries."
>
> That's right, the PEP does not say how the information is to be
> *interpreted*, but it does say what the information is *about* (e.g. a
> certain parameter or the return value).


No it doesn't.  The PEP says what the information's typical use case
is, not what purpose it's mandated for.

You are free to use it for other things.  For example, the following
usage is obvious and sensible (insofar as listing exceptions is
sensible):

def f(x : int) -> int, raises(TypeError)

Think of the return value annotation as more of a function outcome
annotation.  The following are all reasonable uses of it:

def f() -> no_return
def g() -> modifies_argument
def h() -> modifies_global_config
def j() -> raises(StopIteration)


The designers of Python could have added syntax speficially to list
exceptions, but the fact is, the return value annotation can handle
this perfectly well without needing specific syntax.  Python does not
like to add unnecessary syntax.


Carl Banks



More information about the Python-list mailing list