Prototype-Oriented Programming in Python
Project description
Installation
pip install protoclass
Usage
>>> from protoclass import proto
# We create a basic object and add some functionality
>>> jane = proto(first="Jane", last="Doe")
>>> jane.greet = lambda self: print(self)
>>> jane.greet() #doctest: +ELLIPSIS
<proto object at ...>
# A more user-friendly would be better.
# We could modify the `greet` function
# or we could create another object and inherit from it
>>> person = proto(first="", last="")
>>> person.__str__ = lambda self: f"{self.first} {self.last}"
>>> jane = jane.chain(person)
# and we should get a better message.
>>> jane.greet()
Jane Doe
API Reference
proto(attrs) |
Makes a new proto object with given attributes. When no attributes are given, an empty object will be made. |
proto.chain(self, other) |
Makes self inherit from a single prototype. Any relationship with previous parent prototypes will be removed. |
proto.multichain(self, others) |
Makes self inherit from multiple prototypes. Any relationship with previous parent prototypes will be removed. When the parent prototypes share attributes with the same name, the parent prototype that is first in the list of prototypes will provide it. |
clone(proto_object) |
Makes a new proto object that inherits from a single prototype. Equivalent to proto().chain(proto_object). |
multiclone(proto_objects) |
Makes a new proto object that inherits from multiple prototypes. Equivalent to proto().multichain(proto_objects). When the parent prototypes share attributes with the same name, the parent prototype that is first in the list of prototypes will provide it. |
For more information on these functions, call help on the function you would like to know more of, like this: help(proto). You can also read the docs.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.
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
Built Distribution
Hashes for protoclass-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 417c66c56d2fc48e7affb394b3f751a9cf42ee5aed57b6ee903c68e261b63442 |
|
MD5 | 200958e9b51b1ddc28b6ea3d8a9c8b0a |
|
BLAKE2b-256 | 4958a6af2f01a51c7ec86fe694ea5bb46bf6f119269219635bcb5deea1eced71 |