I simply don't understand the point of this. Most likely it's just me being dim but in that case, this code really needs a succinct comment that explains why we need this hack. 
For it makes the code complexity go up. You're relying on `get_role()` in the code but it's virtually impossible to trace its root until you get to this on-the-fly creation of a new class.