I like the idea. In python 3.9 you could actually experiment with implementing something like this yourself using the new Annotated type introduced in PEP 593:
https://docs.python.org/3.9/library/typing.html#typing.Annotated https://www.python.org/dev/peps/pep-0593/ Maybe create a raises helper type and write your annotation like this? from typing import Annotated def divide(numerator: float, denominator: float) -> Annotated[float, raises [ZeroDivisionError]]: return numerator / denominator --- Ricky. "I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler On Thu, Sep 24, 2020 at 8:45 AM Sergio Fenoll <[email protected]> wrote: > Hi, > > I was wondering if the following idea would be a useful addition to the > Python language and if it could use a new PEP. > I personally find myself often looking into the documentation & > implementation of libraries I use to try and figure out what exceptions > a function may raise. > > In the same vein as adding type annotations to code, I think it'd be > very useful to have exception "raises" annotations, i.e. a way to > annotate what exceptions a function raises. Again, like type > annotations, it shouldn't be mandatory nor actually be enforced at > runtime. It would purely serve as a feature that IDEs can make use of. > > An example of how it may look: > > def divide(numerator: float, denominator: float) raises > [ZeroDivisionError] -> float: > return numerator / denominator > > I'd love to know if this is an idea you'd be interested in having added > to the language. > > Kind regards, > Sergio Fenoll > _______________________________________________ > Python-ideas mailing list -- [email protected] > To unsubscribe send an email to [email protected] > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/[email protected]/message/LFUZR6NH35HOLTVGV5YRB6457KZ2KJ5A/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/6IEUEUP7KDZUSV6W5P56JSC2KDBX32NS/ Code of Conduct: http://python.org/psf/codeofconduct/
