Skip to content
Advertisement

How to get a Class and Definitions diagram from Python code?

I have a large multi-file Python application I’d like to document graphically. But first, I made a small “dummy” app to test out different UML packages. (Note: I do have graphviz installed and in the path).

Here’s my “dummy” code:

JavaScript

Here are the different pyreverse command-line codes I’ve used to get varying charts. I’ll post the chart that came closest to what I want below these codes:

JavaScript

Now here is what that last one you see above produces: enter image description here

Finally, in case it is not clear, I’ll reiterate what I want it to show: Classes, Definitions (functions), and – if possible – even variables. But I’d be happy for now to get just Classes and Definitions (functions). To be clear: I want to see function names.

Is it as simple as adding/removing a switch to the pyreverse command? Or is there some package I need to add to my “dummy” code?

Advertisement

Answer

pyreverse aims to produce a class diagram. It will show you classes, and non-filtered class members (see option -f), as well as associations that can be detected. In this regard, the diagram seems complete.

Instances (objects) at top level are not part of a class diagram. This is why pyreverse doesn’t show them.

Free standing functions do not appear in class diagrams either as they are not classes. There is no consensus about what a free standing function should be in UML. They could be seen as instances of a more general function class (of all the functions with the same signature), or they could be considered as a specific functor class. As no UML rule is defined, pyrevere doesn’t show them either. If you want pyreverse to detect them, you should rewrite them as a functor class.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement