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.4.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.4-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file brewinglib_generic-0.0.4.tar.gz.

File metadata

  • Download URL: brewinglib_generic-0.0.4.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.15

File hashes

Hashes for brewinglib_generic-0.0.4.tar.gz
Algorithm Hash digest
SHA256 37f40e847e6851d56261f9e23bf87674b8b0b84900dbee36cbe7742e51bc8255
MD5 dc32ab0c28604293141a40880fe4dec4
BLAKE2b-256 ea0d6b21fd0372eb1795387430616c33782b80217aeeea009240384deace42ac

See more details on using hashes here.

File details

Details for the file brewinglib_generic-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for brewinglib_generic-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a2ecf95144ac7771a877473f2a101f6d7b8fe375828dbd6b008af8a4cfee370c
MD5 df48e7e3568675c2a9d47c1c77c7e3fd
BLAKE2b-256 50c6e03b2784fe0046dfd0683ac3b1dbd1a6c539dc85f8bcf529a10d2dbca4d7

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