On 10/04/20 8:30 am, Soni L. wrote:
Sometimes, you have an API:

     @abc.abstractmethod
     def get_property_value(self, prop):
         """Returns the value associated with the given property.

         Args:
             prop (DataProperty): The property.

         Returns:
             The value associated with the given property.

         Raises:
             PropertyError: If the property is not supported by this config
             source.
            LookupError: If the property is supported, but isn't available.
             ValueError: If the property doesn't have exactly one value.
         """
         raise PropertyError

This doesn't really look like a Python API. It's fairly rare in
Python for exceptions to be used to indicate anything other than
"something unexpected went wrong".

In your unpacking example, the ValueError isn't really intended
as something to be caught under normal circumstances. The assumption
is that you'll know how many items to expect when you unpack something,
and if you don't get that many, then you have a bug.

You could advocate for unpacking to use a more specific exception
to facilitate catching it, but I think most people will consider
your use case to be quite rare.

so my proposal is that we get "exception spaces". they'd be used through the 'in' keyword, as in "except in" and "raise in".

I don't think exceptions are used this way in Python commonly
enough to justify this.

--
Greg
_______________________________________________
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/6GQ553UNUKSHH3UFD24D5ZRZ243TRCOF/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to