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.3rc2.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.3rc2-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file brewinglib_generic-0.0.3rc2.tar.gz.

File metadata

File hashes

Hashes for brewinglib_generic-0.0.3rc2.tar.gz
Algorithm Hash digest
SHA256 314f356ee98a76afbf5b75abe6582aacb13159c73172ac95f2f0ee80f4a5d8d8
MD5 35b827a42b654b72d8f809ed81638b5f
BLAKE2b-256 f9210b438ee85fccb9adc75caccd7fd8b6341b01b8b023441b5a9f9a15529edb

See more details on using hashes here.

File details

Details for the file brewinglib_generic-0.0.3rc2-py3-none-any.whl.

File metadata

File hashes

Hashes for brewinglib_generic-0.0.3rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 7dfe0fc3fcf1f65382a68a6b2acd1693fe3d9cd6b963588423ad92bfeadb2a12
MD5 91d9640f363b5b64c2cb3b3bf7185d70
BLAKE2b-256 e35d1328685451ff87e38f304224c577e1ddf24f85718552a23022a4243e5522

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