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

Uploaded Python 3

File details

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

File metadata

  • Download URL: brewinglib_generic-0.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 2753a682fc4c03080601b609c972bd7b85b048569cfd11b3dcd30d0d423f2e0f
MD5 7f7696a04c96c460d0cba57016409096
BLAKE2b-256 052888a3bb343fa08ddd320666034fb114e13a5e38d6097c9134a07782e0147c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for brewinglib_generic-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 eed93f7dc603188d777facfe61efae99a830ca3f450c99bcfcae82cb2a70cc57
MD5 a91582d50a07686fd7584c410ba9706c
BLAKE2b-256 f059d9df576273a86367fdebc045d2656e0f9a3a44f5e91403825d6f992f417a

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