On Fri, Sep 25, 2020 at 01:23:01PM +0900, Stephen J. Turnbull wrote:
> 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.
pyntch (currently ready for Python 2) can already tell us about exceptions.
Do you know about other tools?
A tiny example:
l=[0,1,2]
with open('f') as fh:
a = int(fh.read())
print(1 / l[a])
command (after fixing option hangling in tchecker.py):
tchecker.py -C show_all_exceptions=True -C raise_uncertain=True p.py
output:
loading: 'p.py' as 'p'
processing: 322 161
processing: 324 6
processing: 328 8
processing: 328 4
processing: 329 2
processing: 332 2
processing: 332 1
processing: 333 2
processing: 333 2
total files=1, lines=4 in 0.05sec
[p (p.py)]
a = <int>
fh = <file>
l = [<int>]
raises IOError: cannot open a file at p:2
raises EOFError: end of file at p:3
raises IndexError: index out of range at p:4
ZeroDivisionError is missing there, however, it couldbe seen as a space for
improvement.
David Kolovratník
_______________________________________________
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/GZW7NXKJMUTK54KTGBCAXMFVIWDKTTFN/
Code of Conduct: http://python.org/psf/codeofconduct/