Skip to main content

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

Project description

1-line decorator to allow a class to be subclassed via generic syntax.

Specifically limited to the pattern where:

  1. a class variable is declared, unbound, as type[T], where T is a generic class parameter.
  2. An arbitary amount of such type parameters can be handled.

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.2rc1.tar.gz (4.6 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.2rc1-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file brewinglib_generic-0.0.2rc1.tar.gz.

File metadata

File hashes

Hashes for brewinglib_generic-0.0.2rc1.tar.gz
Algorithm Hash digest
SHA256 ef01063c64c8d30506990091ab28db3310b18bb529735d731c5c3f9e854da05e
MD5 3f7847901207bcee9277f27d2f62fdd2
BLAKE2b-256 c2173b502e5a7f816cb9e8612ae1915e04311a3003279890e8ce83129ea7f4ed

See more details on using hashes here.

File details

Details for the file brewinglib_generic-0.0.2rc1-py3-none-any.whl.

File metadata

File hashes

Hashes for brewinglib_generic-0.0.2rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c45694affe9938e18c9a79811955b65f05e51a293d101c6563573a64eebe8d8
MD5 9c81ffced972f6292833accc9ba110bc
BLAKE2b-256 5d6477193207f9efc499e9d18ca6fa64031e6207a85f82d51b127877f6659e57

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