Skip to content
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

Type checks in structural.py #22

Open
FChikh opened this issue Oct 19, 2023 · 0 comments
Open

Type checks in structural.py #22

FChikh opened this issue Oct 19, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@FChikh
Copy link
Collaborator

FChikh commented Oct 19, 2023

TL; DR: Python is not strict to types, should we check additionally the types of values assigned to classes' fields, in particularly DomainModel?

I was (still) exploring the features of BUML, and while creating a new DomainModel class, I completed wrong the associations parameter fro constructor: I put there set of ends, but not the set of Association type. Something stupid like this:

# Ends definition
movie_starring: Property = Property(
    name="starring", owner=None, property_type=movie_class, multiplicity=Multiplicity(0, "*"))
star_starred_in: Property = Property(
    name="starredIn", owner=None, property_type=star_class, multiplicity=Multiplicity(0, "*"))

movie_owned_by: Property = Property(
    name="ownedBy", owner=None, property_type=movie_class, multiplicity=Multiplicity(1, 1))
studio_owns: Property = Property(
    name="owns", owner=None, property_type=studio_class, multiplicity=Multiplicity(0, "*"))

# BinaryAssociation definition
relation_stars: BinaryAssociation = BinaryAssociation(
    name="stars", ends={movie_starring, star_starred_in})
relation_owns: BinaryAssociation = BinaryAssociation(
    name="owns", ends={movie_owned_by, studio_owns})

model_cinema: DomainModel = DomainModel(name="Cinema", types={
    movie_class, studio_class, star_class}, associations={movie_starring, star_starred_in, movie_owned_by, studio_owns}, generalizations=None, packages=None, constraints=None)

However, code ran well, I still could properly reach list of associations per class, get their ends etc. It was until the moment I called model_cinema.associations property and tried to call list of ends, like this:

for association in model.associations:
        if len(association.ends) == 2: 
...

And here the code crashed (AttributeError: 'Property' object has no attribute 'ends'), as set of Association was actually a set of Property due to my wrong DomainModel object definition.

For sure, that was caused by wrong declaration of new object, but it seemed to me, that the program should be halted at the moment of wrong definition, not in the runtime after.

@FChikh FChikh added the enhancement New feature or request label Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant