Opened 5 years ago

Last modified 5 years ago

#1216 new enhancement

attribute checking in model definition file

Reported by: pkienzle Owned by:
Priority: minor Milestone: SasView 4.3.0
Component: sasmodels Keywords:
Cc: Work Package: SasModels Infrastructure

Description

sasmodels enhancement.

Don't allow attributes to be added to the ModelInfo class. In the model definition file, don't allow attributes that are not in ModelInfo.

The first part can be done with the following method in the ModelInfo class:

    def __setattr__(self, key, value):
        # Check for class attr when setting; this is because hasattr on
        # a property will return False if getattr on that property raises
        # an exception.  This means if you really want to sneak an
        # attribute into the group from your data loader, you will have
        # to populate it from the
        if not key.startswith('_') and not hasattr(self.__class__, key):
            raise AttributeError("Cannot add attribute %s to class %s"
                                 % (key, self.__class__.__name__))
        object.__setattr__(self, key, value)

The second part will require an additional step at the bottom of modelinfo.make_model_info which scans the attributes of the definition module and makes sure they are in the ModelInfo class. Ignore names with leading underscore so that helper functions and variables can be defined.

By doing this, users will not be able to introduce typos into the model attribute definitions, or otherwise wish for capabilities that are not already there. For example, the model *multilayer_vescicle* defines the following, which looks like it should make *radius* and *n_pairs* polydisperse, but which in fact is completely ignored by sasmodels:

polydispersity = ["radius", "n_pairs"]

Split from ticket #829.

Change History (1)

comment:1 Changed 5 years ago by butler

  • Work Package changed from SasModels Redesign to SasModels Infrastructure
Note: See TracTickets for help on using tickets.