Module: proppy.props

class proppy.props.Property(default_value)[source]

Base class for all properties.

This can be used directly for simple properties with behaviour similar to a normal Python variable. In other cases (i.e. more advanced property features are requiered), a subclass of Property should be used.

Note
Property objects don’t store any data themselves, other than their default value. They simply define the rules for creating, reading and writing a property of a given type.
make_getter(propname)[source]

Creates a function that gets the property

Parameters:propname (str) – The name of the instance-level variable that the property is accessed from
Returns:A function that gets the instance level variable for the property with the specified property name. The name of the instance level variable that is retrieved should be the value of propname with a single underscore before it. The function that is returned takes a single argument: self.
Return type:callable
make_property_init(propname)[source]

Creates a function that intializes the property

Parameters:propname (str) – The name of the instance-level variable that the property will be accessed from
Returns:A function that creates the instance level variable the property with the specified property name. The name of the instance level variable that is created should be the value of propname with a single underscore before it. The function that is returned takes a single argument: self.
Return type:callable
make_setter(propname)[source]

Creates a function that sets the property

Parameters:propname (str) – The name of the instance-level variable that the property is accessed from
Returns:A function that sets the instance level variable for the property with the specified property name. The name of the instance level variable that is written to should be the value of propname with a single underscore before it. The function that is returned (the setter) takes two arguments: self and a the new value.
Return type:callable
class proppy.props.WriteOnceProperty(default_value)[source]

Property that allows only a single assignment, other than the default value.

This property type has a getter and setter like any other property. However, the setter sets a flag after the first assignment that disables further changes to the value. Since the default value is handled separately from the setter, the initial value of a WriteOnceProperty (set in the constructor) does not count as the single allowed assignment.

make_getter(propname)[source]

Creates a function that gets the property

Parameters:propname (str) – The name of the instance-level variable that the property is accessed from
Returns:A function that gets the instance level variable for the property with the specified property name. The name of the instance level variable that is retrieved should be the value of propname with a single underscore before it. The function that is returned takes a single argument: self.
Return type:callable
make_property_init(propname)[source]

Creates a function that intializes the property

Parameters:propname (str) – The name of the instance-level variable that the property will be accessed from
Returns:A function that creates the instance level variable the property with the specified property name. The name of the instance level variable that is created should be the value of propname with a single underscore before it. The function that is returned takes a single argument: self.
Return type:callable
make_setter(propname)[source]

Creates a function that sets the property

Parameters:propname (str) – The name of the instance-level variable that the property is accessed from
Returns:A function that sets the instance level variable for the property with the specified property name. The name of the instance level variable that is written to should be the value of propname with a single underscore before it. The function that is returned (the setter) takes two arguments: self and a the new value.
Return type:callable