>
> I think it'd be very useful to have exception "raises"

annotations, i.e. a way to annotate what exceptions

a function raises.


I personally think this would be wonderful, I've been meaning
to suggest it here for some time, but haven't got around to it.

I first found myself wanting this when I came back to python
having been writing rust. The Result type in rust is somewhat
similar to what's being suggested here. See
https://doc.rust-lang.org/std/result/

This could be initially implemented as a decorator, without
any special syntax required, in fact to avoid excessive line
length, decorators might be the best way to describe
what exceptions can be raised by a function in the long term.

Using a decorator, this could be implemented as a separate
project (and/or extension to mypy) without any changes to the
standard library. it would obviously be a massive piece of work
to build a database of all the exceptions which could be raised
by all standard library functions, let alone 3rd party libraries.

However you could aid 90% of code by covering
10% of methods (or insert your own 80/20, 99/1 ratio). The
point is that the library could be useful long before it was complete
or 100% correct.

In this regard I see a lot of similarities with type hints and
typeshed.

Anyway, thank you Sergio for suggesting this. I really hope
it comes to fruition somehow.

--

Samuel Colvin
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/Y6WJENUAKLHVSAXJOYPMIFKWXCPCYEI7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to