diff --git a/LICENSE b/LICENSE index 261eeb9..d9a10c0 100644 --- a/LICENSE +++ b/LICENSE @@ -174,28 +174,3 @@ of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/README.md b/README.md index c05413c..e68986d 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ from typing import Annotated from data_enum import DataEnum, UNIQUE, UniqueTogether + class Currency(DataEnum): __members__ = ("USD", "EUR", "GBP") @@ -34,6 +35,7 @@ class Currency(DataEnum): name: str code: Annotated[str, UNIQUE] + Currency.USD = Currency(symbol="$", name="US Dollar", code="USD") Currency.EUR = Currency(symbol="€", name="Euro", code="EUR") Currency.GBP = Currency(symbol="£", name="Pound Sterling", code="GBP") @@ -42,24 +44,24 @@ Currency.GBP = Currency(symbol="£", name="Pound Sterling", code="GBP") ### Access data on members ```py -Currency.USD.name # 'US Dollar' -Currency.EUR.symbol # '€' -str(Currency.USD) # 'USD' -repr(Currency.USD) # 'Currency.USD' +Currency.USD.name # 'US Dollar' +Currency.EUR.symbol # '€' +str(Currency.USD) # 'USD' +repr(Currency.USD) # 'Currency.USD' ``` ### Look up members by name ```py -Currency.get("USD") # Currency.USD -Currency.get("MISSING", default=None) # None +Currency.get("USD") # Currency.USD +Currency.get("MISSING", default=None) # None Currency.get("MISSING", default=Currency.USD) # Currency.USD ``` ### Look up by unique attribute ```py -Currency.get(code="EUR") # Currency.EUR +Currency.get(code="EUR") # Currency.EUR Currency.get(code="MISSING", default=Currency.USD) # Currency.USD ``` @@ -77,7 +79,7 @@ Currency.USD == Currency.EUR # False Currency.USD == Currency.USD # True {Currency.USD, Currency.EUR} # works in sets -{Currency.USD: "dollar"} # works as dict keys +{Currency.USD: "dollar"} # works as dict keys ``` ### Default values @@ -93,7 +95,8 @@ class Currency(DataEnum): code: Annotated[str, UNIQUE] active: bool = True -Currency.USD = Currency(symbol="$", name="US Dollar", code="USD") # active=True + +Currency.USD = Currency(symbol="$", name="US Dollar", code="USD") # active=True Currency.EUR = Currency(symbol="€", name="Euro", code="EUR", active=False) # active=False ``` @@ -115,6 +118,7 @@ class State(DataEnum): code: Annotated[str, UniqueTogether("location")] name: str + State.CA_US = State(country="US", code="CA", name="California") State.TX_US = State(country="US", code="TX", name="Texas") State.ON_CA = State(country="CA", code="ON", name="Ontario") @@ -146,7 +150,7 @@ DataEnum uses PEP 681 (`@dataclass_transform`) so type checkers (mypy, pyright, ```py Currency(symbol="$", name="US Dollar", code="USD") # type checker knows these kwargs -Currency(symbol="$") # type checker flags missing args +Currency(symbol="$") # type checker flags missing args ``` ### No-data enums @@ -155,6 +159,7 @@ Currency(symbol="$") # type checker flags missi class Direction(DataEnum): __members__ = ("NORTH", "SOUTH", "EAST", "WEST") + Direction.NORTH = Direction() Direction.SOUTH = Direction() Direction.EAST = Direction() @@ -192,6 +197,7 @@ class Color(DataEnum): __members__ = ("RED", "BLUE") name: str + Color.RED = Color(name="Red") Color.get("RED") # raises ConfigurationError (BLUE not yet assigned) ``` diff --git a/data_enum/__init__.py b/data_enum/__init__.py index 29c8f2c..0db7f24 100644 --- a/data_enum/__init__.py +++ b/data_enum/__init__.py @@ -1,3 +1,4 @@ +# Copyright (C) 2021 Chase Finch """An alternative to the built-in Python `enum` implementation.""" from .data_enum import ( diff --git a/data_enum/_compatibility.py b/data_enum/_compatibility.py index 3fc9226..952f5b6 100644 --- a/data_enum/_compatibility.py +++ b/data_enum/_compatibility.py @@ -1,3 +1,4 @@ +# Copyright (C) 2021 Chase Finch """Back-compatibility shims for supported Python versions. `typing.override` only exists on Python 3.12+, but this package supports diff --git a/data_enum/data_enum.py b/data_enum/data_enum.py index c23bee0..9f9bc30 100644 --- a/data_enum/data_enum.py +++ b/data_enum/data_enum.py @@ -1,3 +1,4 @@ +# Copyright (C) 2021 Chase Finch """An alternative to the built-in Python `enum` implementation.""" from __future__ import annotations diff --git a/requirements/develop.txt b/requirements/develop.txt index cf26bdf..8003206 100644 --- a/requirements/develop.txt +++ b/requirements/develop.txt @@ -8,6 +8,6 @@ docformatter==1.7.8 wemake-python-styleguide==1.7.0 -ruff==0.15.22 +ruff==0.16.0 ty==0.0.61 diff --git a/ruff.toml b/ruff.toml index ac75644..ef3bf5c 100644 --- a/ruff.toml +++ b/ruff.toml @@ -4,6 +4,9 @@ line-length = 99 target-version = "py313" output-format = "grouped" +# The axioms submodule isn't governed by this repo's style +extend-exclude = ["axioms"] + [lint] allowed-confusables = ["\u2018", "\u2019", "\u00d7", "\u2013"] select = ["ALL"] diff --git a/setup.py b/setup.py index 682d3b3..ac2457a 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +# Copyright (C) 2021 Chase Finch """Define metadata for DataEnum.""" from pathlib import Path diff --git a/tests/__init__.py b/tests/__init__.py index 9bae35f..be89eee 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1,2 @@ +# Copyright (C) 2021 Chase Finch """Tests for the DataEnum project.""" diff --git a/tests/test_data_enum.py b/tests/test_data_enum.py index c839e35..0ea7fb0 100644 --- a/tests/test_data_enum.py +++ b/tests/test_data_enum.py @@ -1,3 +1,4 @@ +# Copyright (C) 2021 Chase Finch """Tests for DataEnum.""" import pickle