Missing exceptions in PEP 3107
Christoph Zwerschke
cito at online.de
Fri Aug 15 14:53:57 EDT 2008
Matimus wrote:
> Christoph wrote:
>> Maybe the following syntax would be even more intuitive:
>>
>> def foo(a: "a info", b: "b info") return "ret info" raise "exc info":
>> return "hello world"
>
> That seems much more intuitive and extensible. The "->" syntax has
> always bothered me. The main issue I see with it though is that it
> might be confusing. Consider:
>
> def foo(a, b) return 0:
>
> return a + b
>
> A person reading the code might be tempted to read the annotation and
> think that it is the body. Maybe not a huge problem, but definitely
> something that will come up occasionally.
Yes, that's a drawback; and the same problem for a "raise" clause.
>> Well, yes, but wasn't the whole point of PEP 3107 to get rid of such
>> decorators and provide a single standard way of specifying this kind of
>> info instead?
>
> Maybe, but I think it also does two more things: 1. creates a standard
> location for storing annotations, and 2. Keeps you from violating DRY
> (http://en.wikipedia.org/wiki/DRY).
> Using a single decorator for exception info (or even return info) does
> not violate either of the two stated benefits. The exception
> information would go into the standard annotations dictionary. The
> raises decorator does not violate DRY any more or less than it would
> if added to the language syntax.
That's a valid point, but as you already mentioned, the same applies to
the return value. In my opinion it is desirable that either both return
value and exceptions get a special syntax, or both must be described
using decorators.
-- Christoph
More information about the Python-list
mailing list