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.1rc6.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.1rc6-py3-none-any.whl (2.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for brewinglib_generic-0.0.1rc6.tar.gz
Algorithm Hash digest
SHA256 d9389c97d191c7413fb96e61b3e661db939d3373fa9da17cfc51ccba0440cf47
MD5 718da75e944a38dd0a046c8b4245b798
BLAKE2b-256 7f37c38eb2aa0fed2af7449e86ea2ce4973b310e0ede659b8a22b0640ccfbe04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for brewinglib_generic-0.0.1rc6-py3-none-any.whl
Algorithm Hash digest
SHA256 25b3e19cd8e988ff5a66f6dd514de435070fec087fc501231bdf8d2c3c69720c
MD5 366d8936ddc91de0998b7f70a896b30c
BLAKE2b-256 84aa8de1610ef3d57a534b21e4c2d52ddb0897e0182abcd543642ecf345b948a

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