pyrrole
pyrrole is a Role System for Python3 (3.6 and high). It's inspired by the roles implementation in the Moose library of Perl, and its main purpose is to use instead of Mixin classes and multiple inheritance.
ATTENTION: This package is WIP in alpha release
Test
If you would test before install, follow these instructions:
$ git clone https://github.com/MatteoGuadrini/pyrrole.git
$ cd pyrrole
$ python -m unittest test_role.py
Install
For install this package, run pip install:
$ pip install --user pyrrole
Simple role
Here is an example of how a role can be done:
import pyrrole
class FallFromTree(metaclass=pyrrole.Role):
pass
class Fruit:
pass
@FallFromTree
class Apple(Fruit):
pass
apple = Apple()
print(apple.__roles__)
In this example, the Apple class inherits from Fruit but not FallFromTree.
FallFromTree is a role class that applies to classes so that they acquire the roles attribute.
Role method
By default, all methods or attribute is inherited from a role class except the dunder methods (ex. __str__)..
To force the import of a dunder or normal method, just enclose the method to inherit in a role_method decorator.
import pyrrole
class FallFromTree(metaclass=pyrrole.Role):
@pyrrole.role_method
def __str__(cls):
return f"Fall from tree"
class Fruit:
pass
@FallFromTree
class Apple(Fruit):
pass
apple = Apple()
print(apple)
More roles
An ordinary class can have multiple roles at the same time.
import pyrrole
@pyrrole.role # use role with decorator
class FallFromTree:
def __init__(self, instance):
self.trees = list()
self.trees.append(instance)
def fall(self, tree='tree'):
return f"Fall from {tree}"
@pyrrole.role # use role with decorator
class Deciduous:
def __init__(self, instance):
self.trees = list()
self.trees.append(instance)
def clean_leaf(self):
return f"Clean all leaf"
class Fruit:
pass
@pyrrole.apply_roles(FallFromTree, Deciduous) # apply more role at same time
@pyrrole.rename_role_methods(clean_leaf='clean_apple_leaf') # renamed role names
class Apple(Fruit):
def clean_leaf(self):
return f"Clean all leaf of apple tree"
apple = Apple()
# apple has role?
pyrrole.has_role(apple, FallFromTree) # True
pyrrole.has_role(apple, Deciduous) # True
print(apple.__roles__) # ['FallFromTree', 'Deciduous']
print(apple.clean_apple_leaf()) # method renamed from the Deciduous role
print(apple.fall('apple tree')) # method forced inherited from the FallFromTree role
Open source
pyrrole is an open source project. Any contribute, It's welcome.
A great thanks.
For donations, press this
For me
For Telethon
The Telethon Foundation is a non-profit organization recognized by the Ministry of University and Scientific and Technological Research. They were born in 1990 to respond to the appeal of patients suffering from rare diseases. Come today, we are organized to dare to listen to them and answers, every day of the year.
Acknowledgments
Thanks to Giacomo Montagner for having the idea. Besides, being a contributor he is a great friend!
Thanks to Mark Lutz for writing the Learning Python and Programming Python books that make up my python foundation.
Thanks to Kenneth Reitz and Tanya Schlusser for writing the The Hitchhiker’s Guide to Python books.
Thanks to Dane Hillard for writing the Practices of the Python Pro books.
Special thanks go to my wife, who understood the hours of absence for this development. Thanks to my children, for the daily inspiration they give me and to make me realize, that life must be simple.
Thanks Python!
Metadata
Release files for pyrrole 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyrrole-0.0.7.tar.gz | 16.8 kB | Without provenance | Details for pyrrole-0.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyrrole-0.0.7-py3-none-any.whl | Python 3 | none | any | Details for pyrrole-0.0.7-py3-none-any.whl |
Total release size: 35.4 kB
Release files / pyrrole-0.0.7.tar.gz
| Download URL | pyrrole-0.0.7.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
10f8d447e8ac4f6a947b3d5c9a53ca1dc74a95f1cf74eb6351f5e1e67954914a
|
|
BLAKE2b-256 checksum How to use checksums |
ae081481b3a177657bb3931e988f054080cf737bebc5fe3b6224dabfecd86d8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.6.14
|
Release files / pyrrole-0.0.7-py3-none-any.whl
| Download URL | pyrrole-0.0.7-py3-none-any.whl |
|---|---|
| Size | 18.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4fa4248973b85a411a03c77d8f44c1ed2836e302c97e574dedc4fcdbcaf58d21
|
|
BLAKE2b-256 checksum How to use checksums |
ba57719fe3f5891e2a63690efc2bd10b43159c4ec238f1f063442b8f316d7fea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.6.14
|
Security for pyrrole 0.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.