enum, meta, EnumException
Project description
lifehacks.metaclasses 
Structure
📦 lifehacks.metaclasses
├── meta
├── enum
└── EnumException
Installation
pip install lifehacks.metaclasses
Usage
meta metaclass
There are a few ways to make an meta class.
from lifehacks.metaclasses import meta
class myenum0(metaclass=meta): ...
@meta # preferred method
class myenum1: ...
@meta() # do not use this method
class myenum2: ...
enum metaclass
Same with meta metaclass from above,
there are a few ways to make an enum class.
from lifehacks.metaclasses import enum
# with typing
class MyPalette0(metaclass=enum[Colour]): ...
@enum # preferred method
class MyPalette1: ...
@enum[Colour] # syntax only allowed python>=3.9
class MyPalette2: ...
@enum() # do not use this method
class MyPalette3: ...
usage example:
from lifehacks.metaclasses import enum
@enum
class BasePalette:
BLACK = ...
WHITE = ...
# extending base palette enum
class SubPalette(BasePalette):
RED = ...
GREEN = ...
# can be used in type hinting
def print_colours(palette:enum) -> None:
for name, value in palette:
print(name, value)
print_colours(BasePalette) # BLACK, WHITE
print_colours(SubPalette) # BLACK, WHITE, RED, GREEN
print(BasePalette.BLACK in SubPalette) # True
enum classes are not instantiable, more on that below.
EnumException
enum classes are not instantiable.
If you try to, you get an EnumException
@enum
class Palette: ...
p = Palette() # illegal, raises EnumException
Contributors
- Simon - mightbesimon
- you?
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lifehacks.metaclasses-1.2.2.tar.gz.
File metadata
- Download URL: lifehacks.metaclasses-1.2.2.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fafdec42f5f4fd2548e0a9c06c76bbd972158048d43dabca8d0183520f04406
|
|
| MD5 |
1ebc2100d61a02e72e893af1986d32c9
|
|
| BLAKE2b-256 |
4798742d5c9c55d288f556e8768ad26a0b4e2941534ec388532846cc9c7a29ba
|
File details
Details for the file lifehacks.metaclasses-1.2.2-py3-none-any.whl.
File metadata
- Download URL: lifehacks.metaclasses-1.2.2-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd65ffe54d92caf35bc131f998f443ce38579116c1948a82bf7eb2a4986d96d8
|
|
| MD5 |
f7f2fd4e6d4324c40391c83564515e5b
|
|
| BLAKE2b-256 |
e7c8c823888c1135c3c0294be3a01d026b2bac83c0a7de36b07f37ea59b219e0
|