Skip to content

Commit

Permalink
Merge pull request #2 from jzombie/feature/0.2.1
Browse files Browse the repository at this point in the history
Bump to 0.2.1
  • Loading branch information
jzombie authored Apr 3, 2024
2 parents 4295ac1 + f750eb8 commit 7012713
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
10 changes: 10 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -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/*
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]',
Expand Down

0 comments on commit 7012713

Please sign in to comment.