Coder Social home page Coder Social logo

gidona18 / protoclass Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 283 KB

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

License: Apache License 2.0

Python 100.00%
object-oriented-programming object-oriented prototype prototypes prototypal-inheritance

protoclass's Introduction

protoclass - Prototype-Oriented Programming in Python.

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.

protoclass's People

Contributors

gidona18 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.