I'm trying to create a UML diagram of a python project that shows inheritance relationships between classes using pyreverse.
Here's a small example to reproduce
Foo.py
:
class Foo():
def print_foo(self):
print("hi")
Bar.py
:
from Foo import Foo
class Bar(Foo):
pass
__init__.py
: empty
To generate the diagram, I'm running pyreverse -ASmy -o png .
The resulting diagrams look like this:
classes.png
:
packages.png
:
I would expect the class diagram to show an arrow connecting the two classes, but I can't figure out what I'm missing. Any ideas what's wrong here?
Output of pylint --version
:
pylint 2.14.5
astroid 2.12.10
Python 3.10.5 (main, Jun 6 2022, 18:49:26) [GCC 12.1.0]
If you'd put all your classes in the same file, it works well:
When separating the files as you did, we obtain the result that you show. This suggest that it has to do with the import module name.
If you replace the absolute module name with a relative module name:
from .Foo import Foo
...
Everything works as designed:
P.S: I'm not a python expert. So I could not tell if from Foo
is incorrect and from .Foo
is the way to go because it's a submodule of the current module, or if this is a pyreverse bug. But the pyreverse authors are sometimes here, and maybe they can make a statement. On this other question on composition, the reason was a bug that was expected to be solved in 2.14, but maybe it's a different issue ;-)