Version: (using KDE KDE 3.2.0) Installed from: Mandrake RPMs OS: Linux If I have a subclass with no methods defined, when I generate python code, invalid python classes are generated class A(parent): "docstring" EOF rather than class A(parent): "docstring" pass
It compiles as valid Python for me without the 'pass'. Python 2.3.3c1
Sorry, I did a bad reproduction of the test case. 1) Settings > Configure > Code Generation > Formatting Disable Write documentation if empty, write comments for sections even if section is empty: 2) Generate All Code: #!/usr/bin/env python [...] class new_class: cmg@zinc:~/tmp/uml% python New_class.py File "New_class.py", line 36 Python 2.3 If I include the docstring, it is indeed valid as the class will contain 1 statement.
SVN commit 434449 by okellogg: m_bNeedPass: New flag controls emission of a final "pass" statement. BUG:75454 M +9 -3 pythonwriter.cpp M +2 -0 pythonwriter.h --- trunk/KDE/kdesdk/umbrello/umbrello/codegenerators/pythonwriter.cpp #434448:434449 @@ -34,8 +34,8 @@ #include "../operation.h" #include "../umlnamespace.h" -PythonWriter::PythonWriter( UMLDoc *parent, const char *name ) : -SimpleCodeGenerator( parent, name) { +PythonWriter::PythonWriter( UMLDoc *parent, const char *name ) + : SimpleCodeGenerator(parent, name), m_bNeedPass(true) { } PythonWriter::~PythonWriter() {} @@ -53,6 +53,8 @@ UMLAssociationList aggregations = c->getAggregations(); UMLAssociationList compositions = c->getCompositions(); + m_bNeedPass = true; + //find an appropriate name for our file fileName = findFileName(c,".py"); if (!fileName) { @@ -122,11 +124,15 @@ h<<m_indentation<<":version:"<<m_endl; h<<m_indentation<<":author:"<<m_endl; h<<m_indentation<<"\"\"\""<<m_endl<<m_endl; + m_bNeedPass = false; } //operations writeOperations(c,h); + if (m_bNeedPass) + h << m_indentation << "pass" << m_endl; + //finish files h<<m_endl<<m_endl; @@ -241,7 +247,7 @@ h<<m_indentation<<m_indentation<<"\"\"\""<<m_endl; } h<<m_indentation<<m_indentation<<"pass"<<m_endl<<m_endl; - + m_bNeedPass = false; }//end for } --- trunk/KDE/kdesdk/umbrello/umbrello/codegenerators/pythonwriter.h #434448:434449 @@ -78,6 +78,8 @@ */ void writeOperations(QString classname, UMLOperationList &opList, QTextStream &h, Access access); + + bool m_bNeedPass; ///< True as long as no "pass" has been written }; #endif //PYTHONWRITER