Skip to main content

plain-abc

PyPI version License Build status

Another ABC implementation without metaclass.

It is a little bit annoying to have metaclass conflict, especially when trying to use ABC along with other libraries.

plain-abc provides a simple ABC implementation without metaclass.

Installation

pip install plain-abc

Usage

But you can also use plain-abc to solve the problem:

from abc import abstractmethod

from plain_abc import PlainABC


class _SomeHiddenMetaclass(type):
    pass


class Base(metaclass=_SomeHiddenMetaclass):
    pass


class IFoo(PlainABC):
    @abstractmethod
    def foo(self): ...


class Foo(Base, IFoo):
    def foo(self): ...

To extend an abstract class as another abstract class, PlainABC is required to be one of the bases:

from abc import abstractmethod

from plain_abc import PlainABC


class IEntity(PlainABC):
    @abstractmethod
    def get_id(self) -> str: ...


class IProjectile(IEntity, PlainABC):
    @abstractmethod
    def get_speed(self) -> float: ...


class Arrow(IProjectile):
    def get_id(self) -> str: ...
    def get_speed(self) -> float: ...

To skip signature checking, you can add the member names in __abc_concrete_members__ of a subclass:

from abc import abstractmethod
from enum import Enum

from plain_abc import PlainABC


class IEnum(PlainABC):
    @property
    @abstractmethod
    def foo(self) -> str:
        ...


class Foo(IEnum, Enum):
    # for python 3.10 or lower
    __abc_concrete_members__ = ('foo',)
    foo = 'foo'


assert Foo.foo.value == 'foo'

To solve metaclass conflict without plain-abc

Here is an example of metaclass conflict and how to mix ABCMeta with other metaclasses.

from abc import ABC, ABCMeta, abstractmethod


class _SomeHiddenMetaclass(type):
    ...


class Base(metaclass=_SomeHiddenMetaclass):
    ...


class IFoo(ABC):
    @abstractmethod
    def foo(self): ...


# oh no, metaclass conflict!
# class Foo(Base, IFoo):
#     def foo(self): ...


# create a new metaclass to solve the conflict
class NewMetaclass(_SomeHiddenMetaclass, ABCMeta):
    ...


class Foo(Base, IFoo, metaclass=NewMetaclass):
    def foo(self): ...

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plain_abc-0.1.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plain_abc-0.1.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file plain_abc-0.1.1.tar.gz.

File metadata

  • Download URL: plain_abc-0.1.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for plain_abc-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7b89e7308ed1c5340d15fe2c3bfeb90eb639c4bbba0e6fef0206a7447d3b1ce1
MD5 1d1515ccd5c8d5505bb811e8c0cd2f09
BLAKE2b-256 09b08697790096e45a950673a7f2903ea6b33057fe2e2b06d4eac8d6f9324fde

See more details on using hashes here.

Provenance

The following attestation bundles were made for plain_abc-0.1.1.tar.gz:

Publisher: ci.yml on ChieloNewctle/plain-abc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plain_abc-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: plain_abc-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for plain_abc-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 63f4275327f24f1aca84d8d4bf474551ffd2f1896f413157141ce008cc5605a2
MD5 d86374251e59184f85b4dbb59c8f9da0
BLAKE2b-256 85d641c7ed0c98a2f0a6891eabc0dd5081bce05d756a6b7d2cac67498fd4efe3

See more details on using hashes here.

Provenance

The following attestation bundles were made for plain_abc-0.1.1-py3-none-any.whl:

Publisher: ci.yml on ChieloNewctle/plain-abc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page