O 25/09/20 ás 06:23, Stephen J. Turnbull escribiu:

Sergio Fenoll writes:

  > 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.

I think you need to explain the use cases in more detail.  You mention
IDEs, but they can already grovel through the source code and work out
exactly what exceptions each function explicitly raises, and keep a
database for builtins and the stdlib, which could easily be updated by
the user by running the groveler on Python itself.  3rd party imports,
ditto.  This would allow far more accurate inference of possible
exceptions than an optional 'raises' annotation would.

Even a closed-source vendor removing the .py wouldn't stop a truly
dedicated groveler, I believe.  Because of the way exceptions are
created, there'd be a trace in a namespace in the .pyc or even in a
DLL.

I'm no expert so I'm not sure how IDEs currently handle typing annotations, I assume they make use of the built-in language features for that as opposed to some proprietary solution that every IDE would have to re-implement? If that is the case, i.e. they use a built-in language feature, I think it'd be beneficial to have exception annotations as part of the language as well. Also, if you had a dunder like __raises__ for functions (like you have __annotations__) you could write some cool (and possibly useful?) introspective code.
_______________________________________________
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/A3BPJNCFTEEYKOPZJ6RVHGEJROLTYHPJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to