On Friday, February 9, 2024 at 10:18:45 AM UTC+9 Travis Scrimshaw wrote:

I would be vague about a TypeError versus a ValueError. These are used in 
various ways by different authors over different periods.


Helping an author in choosing the most appropriate one among sometimes 
confusing array of Exceptions is the aim of my proposal. It would be 
impossible to write a guide consistent with existing code in sage. It is 
forward-oriented. No plan to update sage code according to the guide.
 

It can also be very hard to make this rigorous. 


TypeError and ValueError is the most confusing case. Python documentation 
does not help much. Giving a rough definition in sage context would be 
helpful.

For example, for something accepting integer inputs, then 2/2 fails the 
isinstance() check but shouldn't throw an error. Likewise 1/2 is a bad 
value that cannot be tested by the isinstance() check alone. Actually, I 
might consider putting them together and letting the programmer decide 
which is most appropriate (of course, there are clear cases, such as a list 
compared to a number).


 Sorry, I should not have used "isinstance()". I wanted to emphasize that 
TypeError should be used to reject input objects in certain "type" or 
"class" or "set"

For example, if a method accepts a polynomial as input. Then it may emit 
TypeError because the input is a polynomial over symbolic ring while it may 
emit ValueError because the specific input is not appropriate for the 
method to work. Of course, if the input is not a polynomial, this is just 
user's fault (no need to detect this in general)

Right, there is no perfect or rigorous definition. But we may give a 
certain guide or hint with which the author chooses an appropriate one 
between TypeError and ValueError.

In the order of specificity,

INPUT description > TypeError > ValueError > ArithmeticError > 
ZeroDivisionError 

If no other type of error is appropriate, then RuntimeError.

 

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/f951ccd8-439d-4810-b425-f637d5bd67a2n%40googlegroups.com.

Reply via email to