Adds strongly typed property to a class
Project description
StronglyTypedProperty
Sometimes we need to enforce that a property meets certain type and/or value restrictions because the consumers of that property have made assumptions regarding the data that is stored.
The permissiveness of Python to allow anything to be assigned to a property gives us tremendous flexibility but it can also complicate debugging when things go wrong, especially when the wrong data is written into a property. When this happens we will either have an application that runs to completion without failing but gives an incorrect result or we may get an exception thrown at a point-of-use. Either one of these cases can be time consuming to debug depending on the complexity of the application as we need to find where, why, and when the bad data was written to the variable.
While it can be costly to do this checking at each assignment, there are times when we really wish to lock down a property and restrict what can be assigned to it so that any errors will manifest at assignment rather than a use point. In applications that we need to identify exactly where things go wrong quickly (i.e., fail-fast systems) the value of this may well outweigh the hit on performance that we take.
StronglyTypedProperty provides a Data Class like interface with an additional ability to perform strong type checking as well as value checking on the property created. Type checking operations are performed when values are assigned to the property. The following capabilities are provided:
- Restrict assigned data to a list of allowable types.
- Specify the internal sotrage type of the property.
- Set default values (for read before write situations).
- Provide optional value checking on assignment in addition to type checking.
Documentation and User Guide
See the User Guide for detailed documentation on the package. This includes the API docs, user guide, and examples.
History
StronglyTypedProperty is pulled from ConfigParserEnhanced into its own module because it is an interesting and useful class. Splitting these up was the intent from the beginning when it was originally developed.
Updates
See CHANGELOG for information on changes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file stronglytypedproperty-0.1.0.1.tar.gz
.
File metadata
- Download URL: stronglytypedproperty-0.1.0.1.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5694dcecd9c28e4c07df9b3c355c42babee92fd88357f6dee9265931d9de8732 |
|
MD5 | 7e0e2449be204f8765751b154f4d6638 |
|
BLAKE2b-256 | afa560a7c56f661a3f8e43e0e5a6d1013c103fed59a9390a5dd95f4b15a51f6e |
File details
Details for the file stronglytypedproperty-0.1.0.1-py3-none-any.whl
.
File metadata
- Download URL: stronglytypedproperty-0.1.0.1-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 629478d3aa2707f854c938d05cfca26860853a98b90e3935c4f8c7e052949334 |
|
MD5 | 02800e98f626b3a6c1ccdebc5e3ce6fb |
|
BLAKE2b-256 | 5d000dd0a62d481aad1e8aa52770b0d905c38cf43140b8c92517875c4e20990d |