-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document that component attribute must be typed to infer composition relationship #19
Comments
hi @kaungsgit Quick answer Use type annotation to type the value assigned to the component attribute. Then py2puml will infer a composition relationship between the compound class and the component class. Two ways to type the component attribute:
class Dolphin(Mammals):
def __init__(self):
super(Dolphin, self).__init__()
self.fin: DorsalFin = DorsalFin(length=1) # self.fin: DorsalFin class DorsalFin:
def __init__(self, length):
self.length: float = length # self.length: float
class Dolphin(Mammals):
def __init__(self, dorsal_fin: DorsalFin): # dorsal_fin: DorsalFin
super(Dolphin, self).__init__()
self.fin = dorsal_fin class DorsalFin:
def __init__(self, length: float): # length: float
self.length = length Explanation Two kinds of compositions are handled by py2puml:
Your use-case is the 2nd case. There are a couple of unit tests that describe what this library can do, but I believe that the home README.md should better document it: what do you think?
To sum-up what py2puml handles for now in constructors:
# unhandled types from literals
self.name = 'Suzie' # could be detected as a string
self.age = 18 # could be detected as an int
# unhandled types from function calls
self.dorsal_fin = DorsalFin(12)
self.amount = Add(10, 2) I agree that it sound silly to ask people to annotate the type of variable receiving the value of a constructor call (as in Is that ok for you? |
@lucsorel , Thank you very much for your detailed answer. I recently started coding with type hints and I find it easier to read so it is no big deal for me. |
I just have to say that this is working very well for me with the PlantUML plugin in Pycharm. Once I can capture the methods as well in the resulting puml file, this will be GOLDEN!!! Thank you so much again! |
Yes, I should definitely add a documentation section about that. To prevent other users to open issues (thank you for doing it)
For now, the methods are not extracted. My initial goal was to document and understand the complex datastructures handled by an application that I had to maintain, which involved tens of dataclasses (which usually have no methods). Thus, composition and inheritance relationships are handled by py2puml. However, there is an issue open for this feature request: #11. Feel free to contribute if you want, do not hesitate to ask for guidance 😃
It is my pleasure to see that this library helps people, I hesitated to publish and I am glad I did. Thank you for your feedback, which helps improving it. |
Hey @lucsorel , yeah I'm interested in contributing to capture the methods. It'd really make this tool complete for users like myself. I'm new to code inspection so you'll have to give a good amount of guidance there. Also, if you have any ideas on how this can be done, feel free to share as well. Since the attributes are already captured, I'm assuming capturing methods shouldn't be too bad (but I could be wrong). |
document composition relationship: closes #19
Hi,
I tested a simple composition relationship (Dolphin and DorsalFin) and it doesn't seem to work. Only inheritance relationship is captured in the resulting plantUML. Any idea how the composition relationship can be captured?
The text was updated successfully, but these errors were encountered: