Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stronglytypedproperty-0.1.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

stronglytypedproperty-0.1.0-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file stronglytypedproperty-0.1.0.tar.gz.

File metadata

  • Download URL: stronglytypedproperty-0.1.0.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

Hashes for stronglytypedproperty-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9016adf54196c3d8d51b7d42eb4ab675b52395015367f7ff4e3e6b9c15b7ad0c
MD5 a5837acbdb3eba0b9007a51d3c685127
BLAKE2b-256 72cfdeae00dcd37b091a75fd8ce3e0a93b949d08802c04029e72ee232ba787cc

See more details on using hashes here.

File details

Details for the file stronglytypedproperty-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for stronglytypedproperty-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1cf6fdaa6baef32e296cdbfc80f32abffa790cfcbace3d6710b4eabbbbc8b534
MD5 1df3daef07095e4eda19abaf0b72ba47
BLAKE2b-256 4ef3528f9bfadeb72031a85cc46834c6538bb329136a3971add1628938b46a94

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page