24.09.20 11:47, Sergio Fenoll пише: > 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.
Did not the experience of C++ show that exceptions declaration was a bad idea? In C++ it was optional and is abandoned now. Java developers still suffer from necessary to declare all raised exception, or just declare the most general exception class, that makes the feature useless. This may be especially bad for Python where virtually every line of code can raise arbitrary exception. KeybordInterrupt and MemoryError are most common examples, but in rare cases which usually are not covered by tests it can be also UnicodeError, NameError, AttributeError, TypeError, BufferError, etc. _______________________________________________ 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/F244P5HTWU666LZSE3XLULFMNGPZQ27M/ Code of Conduct: http://python.org/psf/codeofconduct/