Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I only use <code>assert</code>s if they provide far better diagnostics than the error messages that I would get otherwise. Your third assert</p> <pre><code>assert(callable(func)) </code></pre> <p>might be an example for such an assert -- if <code>func</code> is not callable, you will get an error message at a completely different line of code than where the actual error is, and it might not be obvious how the non-callable object ended up in <code>self.symbols_map</code>. I write "might" because this depends on the rest of your code -- if this is the only place where <code>self.symbols_map</code> gets updated, the assert might also be unnecessary.</p> <p>The first and last assert definitely are against the idea of duck-typing, <s>and the second one is redundant. If <code>symbol</code> isn't a string of length 1, chances are that <code>self.symbols_map[symbol]</code> will raise a <code>KeyError</code> anyway, so no need for the asserts.</s></p> <p>The last assert is also wrong -- <code>type(keypress)</code> cannot be <code>None</code>, and type checks should be done with <code>isinstance()</code>. There might be very specialised applications where you cannot allow subtypes, but than the check should be performed with <code>type(x) is int</code> instead of <code>type(x) == int</code>. Checking for <code>None</code> should be done by <code>x is None</code>, not by <code>type(x) is NoneType</code>.</p> <p>You should probably write a good set of unit tests -- they will be far more useful than the asserts, and might make almost all of your asserts redundant.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload