Exception.__init__ raises TypeError if overridden and called by subclass
>>> class A(Exception):
... def __init__(self):
... Exception.__init__(self)
...
>>> a = A()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in __init__
TypeError: argument should be a 'Exception' not a 'A'
Why is Exception being enforced here, even if A is a subclass of Exception? That makes it hard to subclass from Exception and override __init__.
Generator `.throw(e, None)` and `.throw(e, None, None)` mishandle already-instantiated exception
Using the web browser Unicorn emulator, haven't verified against newer or other versions:
>>> def g(): yield
...
>>> g().throw(Exception('koz'), None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in g
TypeError: exceptions must derive from BaseException
The expected (what CPython does) behavior is for it to just raise Exception('koz'), same as it would if we didn't pass the second argument at all. Same with when all three arguments are passed in.
The CPython logic for determining when the first argument is allowed to be an exception seems to be based on the second argument either being not passed in or None.
This is not a significant issue and the workaround in calling code is short and simple, but it can cause unexpected and not-obvious breakages deep inside code that otherwise works, and I presume the fix would be trivial for someone who knows where and how .throw is implemented in MicroPython, and I presume it would have almost no performance impact (one conditional inside just the code path of raising exceptions in a generator).