Registry / web-framework / extensionclass

extensionclass

JSON →
library6.3pypypi✓ verified 86d ago

This package provides a metaclass that allows classes implemented in extension modules (typically written in C) to be subclassed in Python. It's primarily used in legacy Python applications, notably within the Zope and Plone ecosystems, to provide features like a class initializer (`__class_init__`) and the acquisition-oriented `__of__` protocol, which predates some modern Python features. The current version is 6.2 and it is actively maintained by the Zope Foundation.

pip install extensionclass
INSTALL
IMPORT
SIG · EXTENSIONCLASS
E
extensionclass
web-frameworkpythonv6.3
Install
1.6s avg
Import
30ms
Disk
16MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v6.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
build_error
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.030s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Base
from ExtensionClass import Base
ExtensionClass
from ExtensionClass import ExtensionClass
ComputedAttribute
from ExtensionClass import ComputedAttribute
For attaching computed attributes to ExtensionClass instances
Method
from ExtensionClass.MethodObject import Method
For creating callable method objects bound to ExtensionClass instances

This example demonstrates the core `ExtensionClass.Base` and its `__of__` protocol, which is central to Zope's acquisition system. When an instance of `Item` is accessed via `container.item1`, the `__of__` method on `Item` is invoked, receiving the `container` as its `parent` argument.

from ExtensionClass import Base class Container(Base): pass class Item(Base): def __init__(self): self.visited = [] def __of__(self, parent): # The __of__ method is called when an Item is accessed # through a parent (acquisition-like behavior). self.visited.append(parent) return self container = Container() item = Item() print(f"Initial item visited list: {item.visited}") # Accessing item through container triggers __of__ container.item1 = item accessed_item = container.item1 print(f"After accessing through container: {item.visited}") # Accessing again demonstrates __of__ being called multiple times accessed_item_again = container.item1 print(f"After accessing again: {item.visited}")
Debug
Known issues
gotchaFor new Python projects, `ExtensionClass` is largely superseded by standard Python 'new-style' classes (available since Python 2.2) which offer similar capabilities for extending classes and often better integrate with modern Python patterns. Unless specifically working with Zope/Plone or similar legacy systems, native Python features are usually preferred.
fix
Evaluate if standard Python class mechanisms (e.g., properties, descriptors, `__slots__`, mixins, or standard inheritance) can achieve the desired outcome without `ExtensionClass`.
affects: All
gotchaThe `__of__` protocol implements 'acquisition', a specific object traversal and context-setting pattern. Misunderstanding how `__of__` binds and rebinds objects can lead to unexpected state or object graph complexities, particularly when objects are referenced from multiple parents or contexts.
fix
Thoroughly understand Zope's acquisition documentation if utilizing `__of__`. Be explicit about object references and their lifetimes to avoid unintended side effects from re-parenting.
affects: All
breakingOlder versions (prior to 4.4) had known issues where C extensions might fail to compile on compatible platforms, leading to installation failures or runtime errors if the pure-Python fallback was not robust.
fix
Ensure `extensionclass` is updated to version 4.4 or higher to benefit from compilation fixes and improved platform compatibility.
affects: <4.4
Errors
Common errors & fixes
AttributeError: 'SomeClass' object has no attribute '__of__'
Attempting to use acquisition-like patterns, or expecting a class to participate in Zope-style acquisition, without it inheriting from `ExtensionClass.Base`.
fix
Ensure the class intended to use `__of__` (or `ComputedAttribute`, `MethodObject` for acquisition-aware behavior) explicitly inherits from `ExtensionClass.Base`: `class MyClass(Base): ...`
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
This error occurs in Python when a class attempts to inherit from multiple bases that have incompatible metaclasses. While not unique to `ExtensionClass`, it can arise if `ExtensionClass.ExtensionClass` is used as a `__metaclass__` alongside another class that implicitly defines a different metaclass.
fix
Refactor the class hierarchy to ensure a single, compatible metaclass is used, or explicitly define a custom metaclass that correctly inherits from all necessary base metaclasses. In modern Python 3, directly assigning `__metaclass__` is less common than inheriting from `type` or another metaclass directly.
Upgrade
Version history
6.3latest on PyPI · released Apr 30, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources
extensionclass — pip install extensionclass · libregistry