Skip to main content

Abstract class attributes

Project description

abcattrs

CI Build Status

Abstract class attributes for ABCs.

import abc
from abcattrs import abstractattrs, Abstract


@abstractattrs
class A(abc.ABC):
    foo: Abstract[int]


# Abstract subclasses can add more required attributes
@abstractattrs
class B(A, abc.ABC):
    bar: Abstract[str]


class C(B):
    # C must define both of these attributes to not raise an error
    foo = 1
    bar = "str"

The Abstract qualifier can be combined with other PEP 593 annotations.

from typing import Annotated
import abc
from abcattrs import abstractattrs, Abstract


@abstractattrs
class A(abc.ABC):
    # Combine with other annotations
    bar: Annotated[str, Abstract, "other info"]

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

abcattrs-0.1.0.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

abcattrs-0.1.0-py3-none-any.whl (6.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page