MakeObj - Powerful Enumeration System
- Author: João Bernardo Oliveira (@jbvsmo)
- Version: 0.9
- GitHub: https://github.com/jbvsmo/makeobj
- Wiki: https://github.com/jbvsmo/makeobj/wiki
MakeObj is a module to help create powerful enumeration classes with support to attributes specific for each element.
This module is compatible with Python versions 2.6+ and 3.0+
Using it
MakeObj lets you create enumerations with a simple language like that:
@obj RGBColors =:
@keys = 'red', 'green', 'blue'
@attr hex = 'ff0000', '00ff00', '0000ff'
@attr is_nice =:
@default = False
@set => 'blue': True
Then you can use like this:
RGBColors = makeobj.parse(text)
if RGBColors.blue.is_nice:
print('I like blue')
print('The hex value of {0.name} is #{0.hex}'.format(RGBColors.red))
If you have simple enums, you can use like this:
RGBColors = makeobj.make('RGBColors', ['red', 'green', 'blue'])
or, with some more data, one may want to write a class:
class RGBColors(makeobj.Obj):
red, green, blue = makeobj.keys(3)
hex = makeobj.attr('ff0000', '00ff00', '0000ff')
Status
This project is in test stage and some issues are expected mainly in the parsing language. It will parse conformant code, but still may not show all the errors and may load an invalid file skipping some data when it should raise an error.
The make function works fine but it may be easier to write a class instead. The
SubObj machinery (see the Wiki entry)
only works in the Enum Language. Yet!
Features
- Enumerations with simple attributes, methods or even small objects with their own attributes.
- An Enumeration Language for easy creation of objects.
- The enumeration by default use the values 0 to N-1 but you may specify your own values.
- The elements of the class are really instances of it and can take advantage of the
isinstancefunction. Because of a metaclass factory, the classes do not share unwanted attributes with the instances. - The elements come with two attributes by default:
nameandvalue(also_nameand_valuein case you want to override them). - Elements can (and should!) be checked with the
iscomparison and can be retrieved by name in string form or value from their class:RGBColors('red')orRGBColors[0]orRGBColors.redresult in the same object. - Enum values must be integer for simplicity and to help usability.
- Subclassing is great!
TODO
- Finalize the specs of MakeObj Enum Language v1.0.
- Change the
@methodproperty to allow better function/method support - Create a helper function to load a directory of
.makeobjfiles as they were a python module. - Better suport on subclassing: multiple inheritance, parent default attributes
Metadata
Release files for makeobj 0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| makeobj-0.9.tar.gz | 16.6 kB | Without provenance | Details for makeobj-0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| makeobj-0.9-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for makeobj-0.9-py2.py3-none-any.whl |
Total release size: 31.0 kB
Release files / makeobj-0.9.tar.gz
| Download URL | makeobj-0.9.tar.gz |
|---|---|
| Size | 16.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3fbd41ad671151953e9479ef107bf3949cb37d1c7089c3c9b2986d07b5be719
|
|
BLAKE2b-256 checksum How to use checksums |
8d9d85fb20b55e5f9e076c16d7f3de2e54745f0c3c4df79e6e684413bd51a4cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.9
|
Release files / makeobj-0.9-py2.py3-none-any.whl
| Download URL | makeobj-0.9-py2.py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
85e0235c731120dd5a7d967ec687f3704161e2825ddaf2b36e134790ae7a506f
|
|
BLAKE2b-256 checksum How to use checksums |
796324b029f3ebae4f3936ecf6eef211f18900bc26c2314b089853d7b985b48e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.9
|
Security for makeobj 0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.