I'm the tiniest bit nervous that you reference self.tag_name without defining it in this class. Obviously I see that you define it in all the other branches, but it would be safer to define some default behavior so you protect yourself from an AttributeError if you forget/don't want to define tag_name in an inherited class.