Bug 75454 - python code generation with purely virtual methods
Summary: python code generation with purely virtual methods
Status: RESOLVED FIXED
Alias: None
Product: umbrello
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Mandrake RPMs Linux
: LO normal
Target Milestone: ---
Assignee: Umbrello Development Group
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-17 21:07 UTC by cmg
Modified: 2005-07-14 07:34 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description cmg 2004-02-17 21:07:15 UTC
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
Comment 1 Jonathan Riddell 2004-02-20 14:24:41 UTC
It compiles as valid Python for me without the 'pass'.
Python 2.3.3c1
Comment 2 cmg 2004-02-20 15:11:26 UTC
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.

Comment 3 Oliver Kellogg 2005-07-14 07:34:05 UTC
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