No comment on the separate namespace for exceptions, but +1 to more
specific exceptions like BroadcastError or InvalidPromotion. They are
more informative, allow users to catch specific errors without pattern
matching the message string, and they would allow putting the relevant
error information in properties rather than just the message (e.g.,
like AxisError does with axis and ndim), which makes for nicer
programmatic access. It would be interesting to see this with
IndexError too, although I'm not sure if it's a good idea to change
the exception type there.

On Fri, Nov 11, 2022 at 11:10 AM Stefan van der Walt
<stef...@berkeley.edu> wrote:
>
> Hi Sebastian,
>
> On Fri, Nov 11, 2022, at 05:46, Sebastian Berg wrote:
> > I would suggest introducing `np.exceptions`.
> >
> > We already have custom errors and warnings:
> >
> > * AxisError
> > * TooHardError  (used by `np.shares_memory()`)
> > * ComplexWarning
> > * RankWarning
> > * VisibleDeprecationWarning
> > * ModuleDeprecationWarning  (not sure what this is)
>
> At first glance, grouping these classes, mainly used internally, into a 
> namespace makes sense to me.
> We also now have the ability to keep them exposed in their old locations for 
> backward compatibility, while not showing them in __all__ and __dir__ (but 
> not even sure that's 100% necessary?).

The new exceptions wouldn't need to go there, but anyone who has ever
wanted to catch one of the existing exceptions will have done "from
numpy import AxisError" or "except np.AxisError". So I think they
would need to stay, or at least go through a deprecation. I personally
have written code that imports VisibleDeprecationWarning.

Aaron Meurer

>
> Stéfan
> _______________________________________________
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> Member address: asmeu...@gmail.com
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to