Skip to main content

No project description provided

Project description

indexed_meta

Python metaclass with support for per-class specialization via an index method.

Adds a __param__ field to classes programmatically so that you can store a static field on them without having to define a new class and without having to use a new name.

from indexed_meta import IndexedMetaclass  # Base type but either will work fine
from indexed_meta import IndexedClass  # Convenience type. Fixes repr(), str()

class Vec(IndexedClass):
    def show(self):
        # This is the value-add for this library. Use __param__ as you see fit.
        # It is different per specialized class but the exact same when param is
        # the same: Vec[1] == Vec[1]; Vec[1] != Vec[2]
        print(self.__param__)

v1 = Vec[3]()
v1.show()  # Prints `3`

Vec[1], Vec[2], Vec[3], Vec[1, 2, 3], Vec[frozenset([1, 2, 3])]

# It's possible to override the default __param__ of None by inheriting from a
# specialized class:
class Vec(metaclass=IndexedMetaclass):
    ...

class Vec4(Vec[4]):
    ...

assert Vec4.__param__ == 4  # Normally it would be `None`

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

indexed_meta-0.0.5.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

indexed_meta-0.0.5-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file indexed_meta-0.0.5.tar.gz.

File metadata

  • Download URL: indexed_meta-0.0.5.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for indexed_meta-0.0.5.tar.gz
Algorithm Hash digest
SHA256 3b5d56232291fca6aa451ca01983e25213d1bce366612d6c465d81f00459699c
MD5 bf341cceeb9b1cd5d0fec0e4a20cf236
BLAKE2b-256 91f62bb4127edd2188ceeeba1a2f05be468c0a648bb9f5122162e2190351374f

See more details on using hashes here.

File details

Details for the file indexed_meta-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: indexed_meta-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for indexed_meta-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2737a971c9e4c502f211e9528cb048ccf76ed03180ad710211b9860a31f11d9f
MD5 ec4384c87a3f83ba93c22f57eb81404b
BLAKE2b-256 cc70d37d0a8082ca253f06e9d52284f3e17252cecad6e7296c0ccfe851c7dad8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page