I'm not familiar enough to say myself, but I assume you've thought about whether this shouldn't be self.document_class.doc_type instead?