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.
class B(A, abc.ABC):
bar: Abstract[str]
class C(B):
# C must assign values to both of these attributes to not raise an error.
foo = 1
bar = "str"
# This raises an error.
class MissingBar(B):
foo = 1
# This raises an error.
class MissingFoo(B):
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"]