Skip to main content

initify.py

The missing magical python decorator for simplifying your __init__(self, ...) function.

@init_args # Magical decorator
def __init__(self, name="Lovely Lucy", age=10):
    pass

p = Person()
p.name # "Lovely Lucy"
p.age  # 10 **Sweet**!

Inherited variables from super class

If you have polymorphism structured classes, you’d love initify.

class Animal(object):
    def __init__(self):
        self.age = 0
        self.name = ""
        self.color = ""
        ...

class Dog(Animal):
    @init_args
    def __init__(self, pet=True):
        pass
    ...

class Cat(Animal):
    @init_args
    def __init__(self, wild=False):
        pass
    ...
d = Dog(age=3, name="Golfy", color="black")
d.age    # 3
d.name   # Golfy
d.color  # black
d.pet    # True

c = Cat()
c.age   # 0
c.name  # ""
c.color # ""
c.wild  # False

That’s dull :/ Don’t judge until you see this:

Exclused variables

# Must declare with new-style class in python 2.7 or earlier
# ``class Animal:`` is fine if using python 3 or later
class Animal(object):
    def __init__(self):
        self.age = 0
        self.name = ""
        self.color = ""
        ...
        self.barks = True  # Only dog barks
        self.meows = True  # and only cat meows
        ...

class Dog(Animal):
    @init_args(exclude=['meows'])  # Don't inherit meows from super class!
    def __init__(self, pet=True):
        pass
    ...

class Cat(Animal):
    @init_args(exclude=['barks'])  # Don't inherit barks from super class!
    def __init__(self, wild=False):
        pass
    ...
d = Dog(age=3, name="Golfy", color="black")
d.age    # 3
d.name   # Golfy
d.color  # black
d.pet    # True
...
d.barks  # True
d.meows  # Attribute Error: meows is not defined!

c = Cat()
c.age   # 0
c.name  # ""
c.color # ""
c.wild  # False
...
d.meows  # True
d.barks  # Attribute Error: barks is not defined!

Now this is neat hey?

Installation

Install initify with pip or pip3.

pip install initify
pip3 install initify

Then whichever class you’re using initify, do an import before using. Example:

from initify import init_args

Now you can attach the decorator @init_args right before the class’s initializer def ___init___(self, ...). Enjoy your effort.

Support

Hope this decorator can help you with your `DRY-iness in your python project!

If you have any suggestion, please don’t hesistate to give a post on the issue page.

Cheers and happy hacking!

Metadata

Release files for initify 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for initify 0.1.5
File Size Uploaded Provenance Actions
initify-0.1.5.tar.gz 2.2 kB Without provenance Details for initify-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for initify 0.1.5
File Interpreter ABI Platform Actions
initify-0.1.5-py2-none-any.whl Python 2 none any Details for initify-0.1.5-py2-none-any.whl

Total release size: 4.5 kB

Release files / initify-0.1.5.tar.gz

Download URL initify-0.1.5.tar.gz
Size 2.2 kB
Tags Source
SHA-256 checksum
How to use checksums
566216661f3becf1675b5bcede6ce33365543b6e75efa56bff652a8bf5dc026d
BLAKE2b-256 checksum
How to use checksums
a4ec09c61fbc9e19e61f0962909baaa64a7683216402465b39f38c57c7d25bb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / initify-0.1.5-py2-none-any.whl

Download URL initify-0.1.5-py2-none-any.whl
Size 2.4 kB
Tags Python 2
SHA-256 checksum
How to use checksums
e02a7df14d76c9fd64f6381b45aa0ca8bb26c3fd1e2949c0ac0eac9cbcd7f3fd
BLAKE2b-256 checksum
How to use checksums
94f9292e1c7292f57b43df688c0108fbebc948c75c23bb505880ff906c796fe0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for initify 0.1.5

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page