Skip to main content

Prototype-Oriented Programming in Python at the tip of your fingers in a simple, easy-to-use library.

Project description

Prototype-Oriented Programming in Python at the tip of your fingers in a simple, easy-to-use library.

PyPI-package-version PyPI-license PyPI-python-versions travis-ci readthedocs PyPI-downloads-month

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 prototype with given attributes. An empty prototype will be made when no attributes are given.

proto.chain(self, other, *others)

Makes self copy attributes from another prototype or multiple other prototypes. Any previous relationship with other parent prototypes will be automatically severed. When parent prototypes share attributes with the same name, the first parent prototype that has that attribute will be provide it, so the order in which they are given matters. Any change made to parent prototypes will be automatically propagated to this prototype.

clone(other, *others)

Makes a new prototype by copying attributes from another prototype or multiple other prototypes. When parent prototypes share attributes with the same name, the first parent prototype that has that attribute will be provide it, so the order in which they are given matters. Any change made to parent prototypes will be automatically propagated to this clone.

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

protoclass-0.5.5.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

protoclass-0.5.5-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file protoclass-0.5.5.tar.gz.

File metadata

  • Download URL: protoclass-0.5.5.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for protoclass-0.5.5.tar.gz
Algorithm Hash digest
SHA256 87a5b844401b799f4b4ad75cd8540c4a6043d593207942780013b3ffc7158e82
MD5 d174b3c68434e80cbc4c74cc431f7355
BLAKE2b-256 d7e7331f4485d188775b0429208ea2ac3b25eec39bd4d875f2b6c27648e9ce31

See more details on using hashes here.

File details

Details for the file protoclass-0.5.5-py3-none-any.whl.

File metadata

  • Download URL: protoclass-0.5.5-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for protoclass-0.5.5-py3-none-any.whl
Algorithm Hash digest
SHA256 af10c62c8d0fb6f10570b58ae5b7719f06bdb2ba51ff82e2701cab8c5c4676aa
MD5 9566ce6a9b1c47f332c8835ecf02911f
BLAKE2b-256 b89c5cb685a9bdbf7a510bf8c0b648bd02488eabc33a5120556a6fd17f9fd2ee

See more details on using hashes here.

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