Skip to main content

Convert a class with generic type parameters to be generic at runtime.

Project description

runtime-generic

Decorator that makes some class's generic be able to be instantiated.

Given a class of type T, decorating with this will allow creation of a subclass with generic parameters mapped to matching unbound class attributes.

Example

from brewinglib.generic import runtime_generic

@runtime_generic
class SomeGenericClass[A, B]:
    attr_a: type[A]
    attr_b: type[B]


class ThingA:
    thinga = "foo"


class ThingB:
    thingb = "bar"


assert SomeGenericClass[ThingA, ThingB]().attr_a.thinga == "foo"
assert SomeGenericClass[ThingA, ThingB]().attr_b.thingb == "bar"

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

brewinglib_generic-0.0.1rc5.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

brewinglib_generic-0.0.1rc5-py3-none-any.whl (2.4 kB view details)

Uploaded Python 3

File details

Details for the file brewinglib_generic-0.0.1rc5.tar.gz.

File metadata

File hashes

Hashes for brewinglib_generic-0.0.1rc5.tar.gz
Algorithm Hash digest
SHA256 324e8a25c4665af1a83d7c9ebacc23a464cc288f4b498f51cb29d46755583b34
MD5 4fb0753ebcf18cdf3a01112f8ba829ce
BLAKE2b-256 538badb0057cfe84b56facade661684568be6eaa11257312fd3b83ffbcbf7cd1

See more details on using hashes here.

File details

Details for the file brewinglib_generic-0.0.1rc5-py3-none-any.whl.

File metadata

File hashes

Hashes for brewinglib_generic-0.0.1rc5-py3-none-any.whl
Algorithm Hash digest
SHA256 72dd8657dc788f1fb4aba06324e3450ed536341cfeaea2f035ab60421ac450dc
MD5 ca63611cc32dd77d3e729159a8d1c933
BLAKE2b-256 8892b0da3e2d0b6e801b9a71d18c4cdc400956c3ea61a1bfff036fa2a60c822f

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