Releases: seequent/properties
Releases · seequent/properties
Release list
v0.3.5 - Revert length conditionals
Bug Fixes
v0.3.4attempted to clean up some code that looked likeif len(val) > 0:to justif val:. This works forlists, but notnp.ndarrays since they have a different way of determining truth. This release reverts these changes back to checking length.
v0.3.4 - ARANZ Branding
Minor Changes
- Properties has been moved under ARANZ Geo Limited branding
auto_createonInstanceproperty has been deprecated (to be removed in a future release)- Instead of using
auto_create, the instance class should be specified asdefault. This will maintain identical behavior.
- Instead of using
v0.3.3 - Modifications to equal and new copy function
Major Features
- New
properties.copyfunction that returns a copy of a HasProperties instance. This method uses serialize and deserialize to create the new instance. (see #147) HasProperties.equalhas been moved toproperties.equal(see #147)- This function determines if all property values on two HasProperties instances are equal
- The movement to a top-level function from HasProperties method sets a precedent for keeping the HasProperties class namespace clean
Minor Changes
- Constraints placed on
equalinput soNoneandproperties.undefinednever reachequal(see #151) - Backwards-compatibility warning - For consistency, in the change notification dictionary
previousis nowproperties.undefinedrather thanNoneif the property value is not defined. This now matches the existing behavior ofvaluein the change notification dictionary beingproperties.undefinedrather thanNoneif the value is deleted. (see #151)
Bug Fixes
properties.Property.equalcould return an iterator rather than a boolean given certain inputs (eg numpy arrays). This method now ensures iterators are reduced to a single boolean. (see #151)
v0.3.2 - Fix intersphinx class links
Bug Fixes
- Fix links in autogenerated docstrings so they point correctly to the new docs introduced in v0.3.1 (see #145)
v0.3.1 - Many New Features: DynamicProperty, Set/Tuple, equal method, etc.
Major Features
New Property types
FileProperty - New Property validated as a file or file name. May providemodeto use for opening a file - ifNone, file must already be open. Also may providevalid_modesfor files that are already open - ifNone, any mode (or file-like objects without mode likeBytesIO) will be valid. (see #100)ImagePNGProperty is now a subclass ofFile. (see #118)
DynamicProperty- New Property created when another property wraps a method. Behaves much like@property, where you can register setters and deleters that use other Properties.DynamicPropertys are never saved to the class. (see #108)SetandTupleProperties - New Properties withsetandtupleunderlying data structures. (see #125)RenamedProperty - for aiding backwards compatibility. (see #126)
Other features
equalmethod onPropertyclasses andHasProperties- This determines if two valid Property values are equal. It is used with
HasPropertiesvalidation to ensure values have been set and validated correctly. (see #124) - Backwards-Compatibility Warning -
HasPropertiesvalidateis now more strict. Rather than simply confirming properties are valid, it confirms that they are valid AND equal to their validated value. This difference is subtle and unlikely to be a problem under normal use. It provides one extra layer of checking that everything was set properly. - New
observerhandler that only fires on change, rather than set. use kwargchange_only=True. (see #125)
- This determines if two valid Property values are equal. It is used with
regexattribute forStringProperty - Ifregexis specified,re.searchon the input string must match the regular expression. (see #117)- Modifications to
StringChoiceProperty (see #120):descriptionsattribute - set this to a dictionary with choice keys and description values for improved documentationcase_sensitiveattribute - determines if choice case should be enforced or just coerced- order of
choicesis now preserved (if applicable)
coerceattribute for container properties (List,Tuple,Set) that ifTrue, allows other container types or individual values (not in a container) as inputs, all of which are coerced to the appropriate container. (see #125)observe_mutationsattribute forListandSetProperties (see #127)- This uses custom container classes that
HasPropertieschange notifications when mutated - Pros: more reliable notifications, Cons: containers are repeatedly copied (bad for large lists/sets)
- This uses custom container classes that
- New method decorator to
stop_recursion_witha specified value if a method gets called recursively on the sameHasPropertiesinstance. (see #121) - New
listeners_disabled/observers_disabled/validators_disabledcontext managers for disablingvalidateandobservehandlers. (see #123, #125) - Enormous overhaul to sphinx docs and docstrings to make the online documentation much more useful. (see #136)
- Backwards-Compatibility Warning - Intersphinx-linked documentation for projects implementing
HasPropertieswill need to rebuild their documentation for links to be correct.
- Backwards-Compatibility Warning - Intersphinx-linked documentation for projects implementing
Minor Changes
- Backwards-Compatibility Warning -
info_textandinfo()have been modified toclass_infoandinforespectively.HasPropertieswith the former attributes will raise aFutureWarningbut still work for now. (see #116) Tasks now have a built-in status report callback (see #122)- Improved
errormessaging wheninstance is Noneand validation of Property attributes. (see #116) - Improved automatic docstring formatting - no longer dependent on Sphinx formatting. (see #119)
InstanceProperties now support old-style classes. (see #116)_defaultsmay now containproperties.undefinedto override previous default values with no default value. (see #136)
Bug Fixes
- Fixed bug where array validation was not raising an error if the
array.type.kindwas not 'i', 'f', or 'b' (see #107)
v0.3.0 - Major update: Serialization, Defaults, Metadata, etc.
Major Features
- Serialization:
- Note:
as_jsonhas been renamedto_jsonfor better parallels betweenfrom_jsonandto_json - Currently serialization/deserialization uses JSON. This can be overridden by registering custom
serializers anddeserializers toPropertyinstances, and possibly overridingserializein aHasPropertiessubclass. All the serialization methods pass around anykwargsthey receive. This allows more flexibility in custom serializers (for example, an open file can be passed around). - In
HasProperties:serializecreates a JSON dictionary of all the properties using the property serialize functions. This dictionary may have a__class__key that stores theHasPropertiesclass for smart deserialization.deserializetakes a dictionary and creates a new instance of theHasPropertiesclass using valid property keywords in the dictionary. Ifdeserializeis used ontrustedJSON, it will use the_REGISTRYto find the correct__class__to construct. If the JSON is nottrusted,deserializeconstructs an instance of the class it is called on.
- In
Propertyclasses and subclasses:to_jsonis a static method that takes a valid property value and converts it to JSON-serializable version. If the value cannot be converted statically (ie aPropertyinstance is required), this errors.from_jsonis a static method that takes a JSON-serializable value and converts it to the a valid property value. Again, if aPropertyinstance is required, this errors.serializetakes a property value and serializes it using either the registeredserializer,to_json, orProperty-subclass-specific serialization logic.deserializetakes a JSON value and deserializes it to a valid property value using either the registereddeserializer,from_json, orProperty-subclass-specific deserialization logic.
- Note:
- Defaults:
defaultswrapper has been removed. To implement dynamic defaults, specify a callable in the_defaultsdictionary - this can no longer depend onself._defaultsdictionary is now inherited. Any defaults not specified in a class will be inherited from parent classes.- This differs from old behaviour where
_defaultsoverwrote parent class values for_defaults
- This differs from old behaviour where
- default values are set before
__init__or with new function_reset. Deleting a property sets it to undefined.- This differs from old behavior where defaults were set on first
getand deleting a property set it to default.
- This differs from old behavior where defaults were set on first
- On init, defaults do not fire change notifications, kwargs do.
- Additional validation of handlers and defaults in the metaclass.
- Metadata tagging:
- Properties can be tagged with additional arbitrary metadata. This is stored on the property in
meta - e.g.
properties.String('password').tag(encrypt=True)
- Properties can be tagged with additional arbitrary metadata. This is stored on the property in
- Dependencies have been reduced for the base
propertiesfunctionality. As a result, installation from PyPI has changed.pip install propertiesonly installspropertiesand the basic requirementsixpip install propreties[math]getsnumpyandvectormathfor the math properties (Arrayis now a math property)pip install properties[image]gets image dependencies (ImagePNG is now native toproperties;properties_image` is no longer needed)pip install properties[full]gets everything
- Beta release support
Minor Changes
- Overriding
__init__has been simplified by moving some instance setup toPropertyMetaclass__call__- By default
__init__now only setskwargs(and fires change notifications)
- By default
Float,Integer, andComplexvalidation has been changed to be more leniant. Intry/except, values are coerced then equality is checked. If both of those pass with no exceptions, the value is valid.- Notably, this allows
numpy.float16and other similar numpy classes that are not subclasses offloat/int/complexto pass validation. - This does not apply for
Bool- values here must be typeboolto pass (eg.numpy.bool8does not pass.
- Notably, this allows
- New
taskmodule for defining for implementing callableHasPropertiesTasks Arrayproperties may now be ofdtypeboolin addition tointorfloat- Exception types:
- Note: changing exception types may introduce backwards-incompatibility in error handling
- No more
AssertionErrorsorKeyErrorsare raised. Now properties raises three types of errors:AttributeErrorson assignment to nonexistent properties/attributesTypeErrorswhenPropertyattributes (e.g.required) are set to invalid valuesValueErrorswhen property values are invalid (i.e. validation onsetfails)
- Terms used to construct properties are now stored on the property for recreating a (possibly modified) version of the property. The
termsattribute is an instance of aPropertyTermsnamedtuple, which contains fields:name,cls,args,kwargsandmeta. StringChoiceproperties now allowsets as input. There is also additional validation to ensure no duplicates are present.filter_propsnow has an option to exclude immutable properties- Minor improvements to doc strings and sphinx docs
- Properties are now alphabetized in the docs (or the order can be customized by setting
_doc_orderto a list of the property names in the desired order).
- Properties are now alphabetized in the docs (or the order can be customized by setting
- Property attributes
helpandhelpdocwere renameddocto remove the name conflict with builtinhelpthis change is not backwards compatible but it is unlikely these attributes are referenced externally anywhere. - Expanded testing
- Video added to README
Bug Fixes
Stringproperties now can handle unicode because casting tostrwas removed.- There is now a
unicodeattribute. IfTrue(default) all strings are coerced to unicode; ifFalsethe input string type is maintained.
- There is now a
- Property
validators (observers that fire on set, before the change) may now coerce the value by modifying thechangedictionary. Previously they were allowed to have a coerced return value, but this value was never used. - Array
dtypevalidation previously allowed bad types to pass as long as 1+ good type was present. Now only good types (int,float, andbool) are allowed.
v0.2.3 - New default behaviour, updated vectormath compatibility
Major Features
- New
defaultbehaviour:defaultvalues are validated but the underlying value is unchanged. This is mostly important when documenting (so, for example, if aColorproperty has a default value'random', "random" shows up in the docs, rather than some coerced RGB triple).startup()has been removed. This was used mainly to instantiate new instances inInstanceproperties and lists inListproperties. Now, if a default value is callable, it is called when accessed._class_defaultis used much more sparingly. Basic properties (ieIntegers andBools) no longer have a class default (other thanundefined). This is only used inListandInstanceclasses but may be defined in otherPropertysubclasses.- Improved determination of default values from nested property classes like
ListandUnionincluding warnings if unused defaults are defined.
- Updated
vectormath:- Now dependent on
vectormath >= 0.1.0(see release notes) - The separation of individual
Vectorclasses vs.VectorArrayclasses is mirrored inproperties- The old
Vector2andVector3are nowVector2ArrayandVector3Arrayproperties and individual vector properties namedVector2andVector3have been introduced.
- The old
- Now dependent on
Minor Changes
requiredis nowTrueby default - This assumes most properties you add to aHasPropertiesclass are there for a reason._exclusive_kwargshas been removed fromHasPropertiesin favour of separatefilter_propsutil function- Immutable
GettablePropertiesare now documented in sphinx as attributes rather than properties. - Extensive cleanup to allow pylint tests to pass
- Minor improvements to README and docs
Bug Fixes
- Class validator functions were not callable on their own; now they are.
v0.2.2 - Sphinx AutoDoc; Improved List, Union, and Instance Properties
New Features
- Sphinx documentation generated for
HasPropertiesclasses in the metaclass based on the class's properties
Minor Changes:
requiredproperties may now havedefaultvalues. On validate, a required property cannot beNoneorundefinedassert_validensuresHasPropertyclasses are valid- List:
Listproperties are now lists of a givenpropertytype. AHasPropertiesclass can also be provided - this is coerced into aninstanceproperty of that class.- validation errors raise list errors rather than errors of the property type
assert_validvalidatesHasPropertiesinstances only- list now has min/max length property
- Union:
- Similar to list,
Unionnow allowsHasPropertiesclasses, coercing them intoInstanceproperties - Union was moved to base from basic
- Similar to list,
- Uid:
assert_validensures the uid has not been tampered with
- Additional testing of the new features
- Improved docstrings
v0.2.1 - Validators
New features:
@properties.validatorwrapper for methods ofHasPropertiesclasses.- If this wrapper is used without arguments, the wrapped function becomes a
ClassValidatorthat is called onhas_props_instance.validate() - If this wrapper is given property name(s) like the
@properties.observerwrapper, then the wrapped function is called on property change.validatorfunctions are called before the change;observerfunctions are called after the change.
- If this wrapper is used without arguments, the wrapped function becomes a
@properties.observe=>@properties.observerrename to matchvalidator
Minor changes:
choicesis now required onStringChoices__init__- this fixes problems with validation of default values (ie trying to set and validate default before the choices are set)
v0.2.0 - Clean API
This is almost a complete rewrite that is more inline with traitlets except that the class namespace is much cleaner. This is quite important as these classes are exposed to interactive use.
This version includes:
- observers
- class _REGISTRY for all subclasses
- better defaults and validators