KarrLab / obj_tables

Tools for creating and reusing high-quality spreadsheets
https://objtables.org
MIT License
8 stars 2 forks source link

Additional features for LocalAttribute class #134

Closed johnsekar closed 4 years ago

johnsekar commented 4 years ago

LocalAttribute class currently contains information on which attributes are related to which other attributes. I would like LocalAttribute class to be more informative, and a general reference point for doing runtime checks in the simulator. To this extent, I would like to have the following features

(Some of this is redundant, but it is useful to access this information from both ends of an edge)

Additionally, it would be useful to encode information about literal attributes as well, such as

Example 1: Simulator processing whether to add an edge between a.foo and b.bar (where foo and bar are attributes) will do:

assert len(a.foo) < a.__class__.Meta.local_attributes['foo'].max_related
assert len(b.bar) < b.__class__.Meta.local_attributes['bar'].max_related
a.foo.add(b)

Example 2: Simulator processing whether to assign a value (current stored in variable x) to attribute a.baz will do:

assert isinstance(x,a.__class__.Meta.local_attributes['baz'].allowed_class)
a.baz = x
jonrkarr commented 4 years ago

This is a good suggestion. I started to annotate the type information in the ObjTables documentation. Incorporating the type information directly into ObjTables is even better.

I added these properties to LocalAttribute

I also added type and related_type to Attribute and set the values for every subclass of Attribute. The values are either a Python type (i.e. a class) or a tuple of Python types -- both are valid arguments of isinstance. The tuple form is used when the value can be None. For example: