Skip to main content

Collection of python extras, like decorator @dynamicmethod

Project description

The Trojan Rabbit

A collection of python extras (and an hommage to Monty Python's Holy Grail)

Decorator @dynamicmethod

This decorator provides the missing option for method definitions:

| decorator           | 1st parameter passed when called from |
|                     | instance / class                      |
|---------------------+---------------------------------------|
| - (instance method) | instance / None                       |
| @classmethod        | class    / class                      |
| @staticmethod       | -        / -                          |
| @dynamicmethod      | instance / class                      |

Usage

from trojan_rabbit.dynamicmethod import dynamicmethod


class Knight:
    description = "a knight of the Round Table"

    def __init__(self, name, attribute):
        self.name = name
        self.attribute = attribute

    @dynamicmethod
    def whoami(caller):
        if isinstance(caller, Knight):
            print(f"{caller.attribute.capitalize()} Sir {caller.name}", end=', ')
        print(caller.description)


robin = Knight("Robin", "brave")

Knight.whoami
# output: <bound method Knight.whoami of <class '__main__.Knight'>>

robin.whoami
# output: <bound method Knight.whoami of <__main__.Knight object at 0x7f377073fe50>>

Knight.whoami()
# output: a knight of the Round Table

robin.whoami()
# output: Brave Sir Robin, a knight of the Round Table

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

trojan_rabbit-0.0.1.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trojan_rabbit-0.0.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file trojan_rabbit-0.0.1.tar.gz.

File metadata

  • Download URL: trojan_rabbit-0.0.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for trojan_rabbit-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4668b023a58f89055eaf9105a29b0a03e1dc367fc416df0c30781db190b328e7
MD5 34652e40ae8411e80305f0be5573694d
BLAKE2b-256 396c6e5e7d366f7b08c21e46940aed221610dcfa35cfb3ef0f84cf8211643fb6

See more details on using hashes here.

File details

Details for the file trojan_rabbit-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: trojan_rabbit-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for trojan_rabbit-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f1bf29b014b1feb634ed29b9df7017b4377785aa0cb2208ba5b627d031f5db1e
MD5 e41867c76262d808728b5f935bd6af64
BLAKE2b-256 48f897e1f607e61f3e33c8e094c3c445f829151c9470ad1b254bfa111927d855

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page