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/fast_enum/fastenum.py b/fast_enum/fastenum.py index 435aabb..b8bb32e 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.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'))) for attr in attributes: if attr in namespace: @@ -88,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): @@ -186,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 diff --git a/setup.py b/setup.py index a9beb70..d5a896d 100644 --- a/setup.py +++ b/setup.py @@ -4,8 +4,8 @@ long_description = rfd.read() setuptools.setup( - name='fast-enum', - version='1.3.0', + name='fastenumplus', + version='1.4.0', license='MIT', platforms=['any'], author='Andrey Semenov', @@ -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',