Package: customdataclass
CustomdataclassCustom implementation of thedataclassmodule from the standard Python library as a base class for other dataclasses.
The documentation is availablehere.DetailsA while back I was working on a project(now lost in a dusty corner of my GitHub profile)that required me to create a lot of data structures(variables used only to hold complex data)and I quickly realised that using dictionaries(or named dictionaries)was slowly becoming messy because:dictionaries are mutabledictionary keys are strings and there's no easy way to set a default value for a keythere's no way to ensure that a dictionary is well-formedcomplex attributes that are needed once or twice cannot be generated on the fly and must be stored in the dictionaryAfter a quick Google-fu session, I found out the existence of thedataclassdecorator, swiftly provided by thedataclasses. This decorator allows you to create a class that is used only to hold data, and it provides a lot of useful features, such as:default values for attributespre-determined methods(such as__init__,__repr__, etc.)However, it does not handle easily features like:complex attributes(i.e. attributes that are dataclasses themselves)nested dataclasses(i.e. a dataclass that has another dataclass as an attribute)serialization and deserializationhashing and equalitytype checkinginheritanceAll these were important for the project(which once again will be finished, one day)and so I decided to create a custom class that would handle all these features.I chose to create a class(and not a decorator)because I wanted to be able to inherit from it and to be able to use it as a base class for other dataclasses, thus solving the aforementioned problems.Provided featuresdefault values for attributestype checking(can be deactivated)nested dataclasses(i.e. a dataclass that has another dataclass as an attribute)frozen dataclassesa dataclass cannot be modified after its creation(if the parameterfrozenis set toTrue, as per default)otherwise, a dataclass can be manually frozen using thefreezemethodequality comparison(via the__eq__method)hashing(via the__hash__method)full support inheritancefull support for methods overriding and custom propertiesInstallingThe package is available on PyPI and can be installed usingpip:pipinstall-ucustomdataclassExamplesExamples can be found in theexamplesfolder, both in a text fileEXAMPLES.mdand in a set of Python scripts.TestsUnit tests can be found in thetestsfolder.
Currently, the code coverage for unit tests is close to 100%.Running the testsTo run the tests, simply run the following command from the root folder of the project:python3-munittestdiscover-v-s./tests-p"test*.pyIf you're using VScode, you can also use theRun Testscommand from thePython Test Explorer for Visual Studio Codeextension.Computing the coverageTo compute the coverage, simply run the following commands from the root folder of the project:coverage run -m unittest discover -s ./tests -p "test*.py"coverage report -mto see the report in the terminalcoverage htmlto see format the report in HTML and see it in the browserDocumentationDocumentation can be found in thedocsfolder of the repo and on thispage.Building the documentationTo build the documentation, simply run the following command from thesrcfolder of the project:pdoc--html-o../docscustomdataclass.py--forceContributingPull requests, bug reports and feature requests are more than welcome!Thank you for your interest in this silly little project of mine!LicenseThis project is licensed under the MIT License - see theLICENSE.mdfile for details