Releases: jetavator/wysdom
0.3.0-rc1
Enhancements
-
#64 - Allow property type in user property to be a python enum and translate it to a jsonschema enum
Sometimes a property should have one of a set of strictly enumerated values.
For this use case it is possible to use a PythonEnum
as the property type
of a givenwysdom.UserProperty
:from enum import Enum class Color(Enum): PINK = "pink" ORANGE = "orange" class Vehicle(UserObject): color = UserProperty(Color) >>> my_vehicle = Vehicle({"color": "orange"}) >>> my_vehicle.color <Color.ORANGE: 'orange'>
-
#65 - Regular expression support
If you need to restrict the values that a UserProperty
can take according to a regex pattern, you can specify this
using thepattern
parameter::class Vehicle(UserObject): rgb_hex_color = UserProperty(str, pattern=r"^[0-9a-f]{6}$")
If your dictionary only has certain keys that are valid for your application
according to a regex pattern, you can specify this with the parameter
key_pattern
:color_names = UserProperty( SchemaDict(ColorName), key_pattern=r"^[0-9a-f]{6}$" )
-
#66 - Convenience function: properties
Introduces the convenience function
wysdom.properties
so that:for name, parameter in MyObject.__json_schema_properties__.properties.items():
can be simplified to:
for name, parameter in wysdom.properties(MyObject).items():
-
#67 - Convenience classes: ListProperty and DictProperty
Introduces the convenience classes
wysdom.ListProperty
andwysdom.DictProperty
so that:people_list = UserProperty(SchemaArray(Person))
can be simplified to:
people_list = ListProperty(Person)
and
people_dict = UserProperty(SchemaDict(Person))
can be simplified to:
people_dict = DictProperty(Person)
0.2.3
0.2.2
0.2.1
0.2.0
Enhancements
#47 - Allow multiple subclasses of RegistersSubclasses to have the same register_as value. Classes and instances returned by registered_subclass
and registered_subclass_instance
are now always strict subclasses of the class invoking the method, and will only throw a KeyError if there are multiple valid subclasses with the same key. See the docstring for RegisteredSubclasses.registered_subclass
for more details.
Compatibility Changes
#47 - Please note that this update breaks backward compatibility on RegisteredSubclasses.registered_subclasses
which now returns Dict[str, List[Type[RegistersSubclasses]]]
instead of Dict[str, Type[RegistersSubclasses]]
. If you have existing code that uses this method, please replace calls to RegisteredSubclasses.registered_subclasses()
with RegisteredSubclasses.registered_subclasses()[0]
.
0.1.5
Enhancements
- #45 - added parameter
persist_defaults
to UserProperty. If this parameter is set to True and a UserProperty also has either thedefault
ordefault_function
parameter , when the UserProperty returns a default value that value will also be explicitly stored in the underlying data object. This was the default behavior before 0.1.4. This is often desirable behavior if the UserProperty returns another object and your code expects it to return the same object instance each time it is accessed, and so is now provided as a configurable parameter.
Bug fixes
- #42 - default values of a
UserProperty
will now be returned as the type declared inproperty_type
, as before 0.1.4
0.1.4
0.1.3
0.1.2
Enhancements
- #28 - added function wysdom.schema to look up an object's schema, allowing jsonschema validation checks in the style
schema(element).is_valid(instance)
- #33 - JSON schemas are now built using named references, meaning it is now possible to have recursive schemas (e.g. Person objects containing other Person objects)
Bug fixes
- #30 - object schemas not being correctly rendered as dicts when members of a SchemaArray
Technical changes
- #31 - new implementations of copy and deepcopy
Documentation
- #37 - completed initial user guide and API documentation