From e28bccf683acfda9ea23cb044b9dcafbbb152692 Mon Sep 17 00:00:00 2001 From: Hiddify <114227601+hiddify-com@users.noreply.github.com> Date: Thu, 1 Feb 2024 21:18:32 +0000 Subject: [PATCH 1/6] fix: bug that not accept lower case --- fast_enum/fastenum.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fast_enum/fastenum.py b/fast_enum/fastenum.py index 435aabb..0aec4b5 100644 --- a/fast_enum/fastenum.py +++ b/fast_enum/fastenum.py @@ -53,10 +53,9 @@ class FastEnum(type): # pylint: disable=bad-mcs-classmethod-argument,protected-access,too-many-locals # pylint: disable=too-many-branches def __new__(mcs, name, bases, namespace: Dict[Text, Any]): - attributes: List[Text] = [k for k in namespace.keys() - if (not k.startswith('_') and k.isupper())] - attributes += [k for k, v in namespace.get('__annotations__', {}).items() - if (not k.startswith('_') and k.isupper() and v == name)] + slots=set(namespace["__slots__"]) + attributes: List[Text] = [k for k,v in namespace.items() + if (not k.startswith('_') and k not in slots and not callable(v))] light_val = 0 + int(not bool(namespace.get('_ZERO_VALUED'))) for attr in attributes: if attr in namespace: From b86fd52943aa3079a31765b19362360befab739d Mon Sep 17 00:00:00 2001 From: Hiddify <114227601+hiddify-com@users.noreply.github.com> Date: Thu, 1 Feb 2024 21:26:55 +0000 Subject: [PATCH 2/6] bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a9beb70..5ac5d77 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name='fast-enum', - version='1.3.0', + version='1.4.0', license='MIT', platforms=['any'], author='Andrey Semenov', From 37339a5f2c29cc6e17bed7e5adc64f516ef20263 Mon Sep 17 00:00:00 2001 From: Hiddify <114227601+hiddify-com@users.noreply.github.com> Date: Thu, 1 Feb 2024 21:45:54 +0000 Subject: [PATCH 3/6] fix: bug --- fast_enum/fastenum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast_enum/fastenum.py b/fast_enum/fastenum.py index 0aec4b5..8d1b5d3 100644 --- a/fast_enum/fastenum.py +++ b/fast_enum/fastenum.py @@ -53,7 +53,7 @@ class FastEnum(type): # pylint: disable=bad-mcs-classmethod-argument,protected-access,too-many-locals # pylint: disable=too-many-branches def __new__(mcs, name, bases, namespace: Dict[Text, Any]): - slots=set(namespace["__slots__"]) + slots=set(namespace.get("__slots__",{})) attributes: List[Text] = [k for k,v in namespace.items() if (not k.startswith('_') and k not in slots and not callable(v))] light_val = 0 + int(not bool(namespace.get('_ZERO_VALUED'))) From 62026a1fc7618154dc4e4fec0febb7ba00954edc Mon Sep 17 00:00:00 2001 From: Hiddify <114227601+hiddify-com@users.noreply.github.com> Date: Thu, 1 Feb 2024 22:26:07 +0000 Subject: [PATCH 4/6] new: add __member__ to make it similar to enum --- fast_enum/fastenum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast_enum/fastenum.py b/fast_enum/fastenum.py index 8d1b5d3..531a961 100644 --- a/fast_enum/fastenum.py +++ b/fast_enum/fastenum.py @@ -87,7 +87,7 @@ def __new__(mcs, name, bases, namespace: Dict[Text, Any]): namespace['__dir__'] = partial(FastEnum.__dir, bases=bases, namespace=namespace) typ = type.__new__(mcs, name, bases, namespace) if attributes: - typ._value_to_instance_map = {} + typ.__members__=typ._value_to_instance_map = {} for instance_name in attributes: val = namespace[instance_name] if not isinstance(val, tuple): From d2245348276029f4f9ae282b3f762f38643d2189 Mon Sep 17 00:00:00 2001 From: Hiddify <114227601+hiddify-com@users.noreply.github.com> Date: Thu, 1 Feb 2024 23:55:45 +0000 Subject: [PATCH 5/6] new: add missing value support similar to basic enum --- fast_enum/fastenum.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fast_enum/fastenum.py b/fast_enum/fastenum.py index 531a961..b8bb32e 100644 --- a/fast_enum/fastenum.py +++ b/fast_enum/fastenum.py @@ -185,7 +185,9 @@ def __delattr__(cls, item): super().__delattr__(item) def __getitem__(cls, item): - return getattr(cls, item) + if hasattr(cls,'__missing__') and hasattr(cls,item): + return getattr(cls, item) + return cls.__missing__(item) def has_value(cls, value): return value in cls._value_to_instance_map From 078d68fab167f06cd265d8bda3584c2bae485793 Mon Sep 17 00:00:00 2001 From: Hiddify <114227601+hiddify-com@users.noreply.github.com> Date: Sat, 17 Feb 2024 12:02:22 +0000 Subject: [PATCH 6/6] new: add build --- .github/workflows/release.yaml | 32 ++++++++++++++++++++++++++++++++ setup.py | 4 ++-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..46ad3c6 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,32 @@ +name: Upload Python Package + +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - '*' # Push events to matching v*, i.e. v1.0, v20.15.10 + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: +permissions: + contents: write +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine gitchangelog pystache + - name: Build and publish + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* \ No newline at end of file diff --git a/setup.py b/setup.py index 5ac5d77..d5a896d 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ long_description = rfd.read() setuptools.setup( - name='fast-enum', + name='fastenumplus', version='1.4.0', license='MIT', platforms=['any'], @@ -13,7 +13,7 @@ description='A fast pure-python implementation of Enum', long_description=long_description, long_description_content_type='text/markdown', - url='https://github.com/QratorLabs/fastenum', + url='https://github.com/hiddify/fastenum', packages=['fast_enum'], classifiers=[ 'License :: OSI Approved :: MIT License',