You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bad error message when Should Be Equal compares items that have same string representation but different type #817
If you compare e.g. string "1" and number 1 with Should Be Equal, you get error message telling 1 != 1. This is obviously really confusing and the keyword should definitely report the item types in this case.
Some possible ways to solve this are below:
Report item types in the error message if the string representation is same but types different. For example 1 (string) != 1 (number).
Report types always when they are different. So also 1 (string) != 2 (number).
Only log the types and keep the error message as it. This could be done always, even then types are same, and would be trivial to implement.
Combination of 1) and 3).
Notice that in above examples types have been converted to human readable format like str -> string and int -> number.
Originally submitted to Google Code by bryan.oakley on 14 Apr 2011
I would vote for always using the data type, but not in parenthesis. Using the parenthesis means I have to mentally parse the string. If it reads as plain English the meaning is immediately clear. For example, "integer 'x' != string 'y'" or "string 'y' != integer 'x'" or "float 'x' != integer 'y'". The meaning of "string 'x' != string 'y'" is also immediately apparent.
A problem with showing the types always, even when they are same, is that messages that you get with custom objects can be pretty cryptic. If types are not shown always, they should be, in my opinion, clearly separated from the value with parenthesis or otherwise.
I've been thinking about this a bit more and start to like the idea of always logging the types and including them to the error only when string representation is same.
We decided to implement this using the approach 4.
Types of the arguments are always logged as returned by type() function. Type information is added to the error message only if the string representation differ, and in this case it is shown in format
Activity
spooning commentedon Jun 29, 2014
I would vote for always using the data type, but not in parenthesis. Using the parenthesis means I have to mentally parse the string. If it reads as plain English the meaning is immediately clear. For example, "integer 'x' != string 'y'" or "string 'y' != integer 'x'" or "float 'x' != integer 'y'". The meaning of "string 'x' != string 'y'" is also immediately apparent.
spooning commentedon Jun 29, 2014
A problem with showing the types always, even when they are same, is that messages that you get with custom objects can be pretty cryptic. If types are not shown always, they should be, in my opinion, clearly separated from the value with parenthesis or otherwise.
I've been thinking about this a bit more and start to like the idea of always logging the types and including them to the error only when string representation is same.
spooning commentedon Jun 29, 2014
We decided to implement this using the approach 4.
Types of the arguments are always logged as returned by type() function. Type information is added to the error message only if the string representation differ, and in this case it is shown in format
1 (string) != 1 (number)