From f750eb8fa6f3dfc0c84688616f0d36e2b5ddc08c Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Wed, 3 Apr 2024 14:10:41 -0500 Subject: [PATCH] Bump to 0.2.1 --- README.md | 25 +++++++++++++++++++++++++ makefile | 10 ++++++++++ setup.py | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 makefile diff --git a/README.md b/README.md index 60f5d8e..ec882f8 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ - **to_dict**: Convert an enum class to a dictionary representation, mapping member names to their values. - **get_initial**: Retrieve the first value defined in the enum, useful for cases where a default or initial value is needed. +- **get**: Mimics the dictionary `get` method, allowing retrieval of enum values with an optional default fallback. + ## Installation @@ -45,6 +47,29 @@ print(initial_color) # Output: 'red' ``` +### Using the `get` Method + +Retrieve an enum value by its name, with an option to specify a default value if the name does not exist. + +## Get a value for an existing key + +```python +print(Color.get('RED')) # Output: 'red' +``` + +## Get a value for a non-existing key with a default value + +```python +print(Color.get('PURPLE', default='unknown')) # Output: 'unknown' +``` + +## Get a value for a non-existing key, falling back to the initial value + +```python +print(Color.get('PURPLE')) # Output: 'red' +``` + + ## LICENSE `EnumWithDict` is released under the MIT License. See the [LICENSE](LICENSE) file for more details. diff --git a/makefile b/makefile new file mode 100644 index 0000000..17db084 --- /dev/null +++ b/makefile @@ -0,0 +1,10 @@ +.PHONY: build publish + +build: + python setup.py sdist bdist_wheel + +publish-test: + twine upload --repository-url https://test.pypi.org/legacy/ dist/* + +publish: + twine upload dist/* diff --git a/setup.py b/setup.py index 085e5b3..aa4b9f3 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='enum_with_dict', - version='0.2.0', + version='0.2.1', packages=find_packages(), author='Jeremy Harris', author_email='jeremy.harris@zenosmosis.com',