Package: pyproprop
Package for aiding writing classes with lots of similar simple properties without the boilerplate.StatusLatest ReleaseDocsPyPIAnacondaCoverageLicenseWhat is Pyproprop?Do you often find yourself writing classes with properties such as:fromsome_other_moduleimportDefaultObject,some_typeclassExampleClass:def__init__(self,type_checked_value,bounded_numeric_value,specific_length_sequence_value,obj_with_method_applied_value,):self.type_check_attr=type_checked_valueself.bounded_numeric_attr=bounded_numeric_valueself.specific_length_sequence_attr=specific_length_sequence_valueself.obj_with_method_applied_attr=obj_with_method_applied_valueself.instantiate_default_if_none_attr=None@propertydeftype_checked_attr(self):returnself._type_checked_attr@type_checked_attr.setterdeftype_checked_attr(self,val):ifnotisinstance(val,some_type):msg="`type_checked_attr` must be of `some_type`"raiseTypeError(msg)self._type_checked_attr=val@propertydefbounded_numeric_attr(self):returnself._bounded_numeric_attr@bounded_numeric_attr.setterdefbounded_numeric_attr(self,val):val=float(val)lower_bound=-1.0upper_bound=2.5ifval<lower_bound:msg=f"`bounded_numeric_attr` must be greater than{lower_bound}"raiseValueError(msg)ifval>=upper_bound:msg=(f"`bounded_numeric_attr` must be less than or equal to "f"{upper_bound}.")raiseValueError(msg)self._type_checked_attr=val@propertydefspecific_length_sequence_attr(self):returnself._specific_length_sequence_attr@specific_length_sequence_attr.setterdefspecific_length_sequence_attr(self,val):iflen(val)!=2:msg="`specific_length_sequence` must be an iterable of length 2."raiseValueError(msg)self._specific_length_sequence_attr=val@propertydefobj_with_method_applied_value(self):returnself._obj_with_method_applied_value@obj_with_method_applied_value.setterdefobj_with_method_applied_value(self,val):val=str(val)self._obj_with_method_applied_value=val.title()@propertydefinstantiate_default_if_none_attr(self):returnself._instantiate_default_if_none_attr@instantiate_default_if_none_attr.setterdefinstantiate_default_if_none_attr(self,val):ifvalisNone:val=DefaultObject()self._instantiate_default_if_none_attr=valWithPypropropall of this boilerplate can be removed and instead the exact same class can be rewritten as:frompypropropimportprocessed_propertyfromsome_other_moduleimportDefaultObject,some_typeclassExampleClass:type_checked_attr=processed_property("type_checked_attr",description="property with enforced type of `some_type`",type=some_type,)bounded_numeric_attr=processed_property("bounded_numeric_attr",description="numerical attribute with upper and lower bounds"type=float,cast=True,min=-1.0,max=2.5,)specific_length_sequence_attr=processed_property("specific_length_sequence_attr",description="sequence of length exactly 2",len=2,)obj_with_method_applied_attr=processed_property("obj_with_method_applied_attr",description="sting formatted to use title case"type=str,cast=True,method="title",)instantiate_default_if_none_attr=processed_property("instantiate_default_if_none_attr",default=DefaultObject,)def__init__(self,type_checked_value,bounded_numeric_value,specific_length_sequence_value,obj_with_method_applied_value,):self.type_check_attr=type_checked_valueself.bounded_numeric_attr=bounded_numeric_valueself.specific_length_sequence_attr=specific_length_sequence_valueself.obj_with_method_applied_attr=obj_with_method_applied_valueself.instantiate_default_if_none_attr=NoneInstallationThe easiest way to installPypropropis using theAnaconda Python distributionand its includedCondapackage management system. To installPypropropand its required dependencies, enter the following command at a command prompt:condainstallpypropropTo install using pip, enter the following command at a command prompt:pipinstallpypropropFor more information, refer to theinstallation documentation.ContributeIssue Tracker:https://github.com/brocksam/pyproprop/issuesSource Code:https://github.com/brocksam/pypropropLicenseThis project is licensed under the terms of theMIT license.