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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for brewinglib_generic-0.0.3rc1.tar.gz
Algorithm Hash digest
SHA256 992410d3548d1176f3511ef39e32a6f70e539f13c548e903aa389e0ad6e0c455
MD5 cf4e9953a88b8dc4c6e7f14d9b5df18f
BLAKE2b-256 a9ac35a6af787f706268602c4dd31a0f6a3ba3978c4aff6658fab472067cfc8b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for brewinglib_generic-0.0.3rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 c7947fedb0fd2fed814c6d0a932718ca03ce2a45a75db70262c6fb82b7e08554
MD5 7e953f59f82c042b423982192cd8d7ab
BLAKE2b-256 0015c91884e42736124ff9aeacc708f6b2a4568851985f5ff7e4dc2524f88cfb

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