Skip to content

A project highlighting the pitfalls of Python wildcard imports, overridden magic methods, and unexpected class behaviors πŸ°πŸ’» @recursecenter

Notifications You must be signed in to change notification settings

bdelanghe/dark-magics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ°πŸ’» Dark Bunnies: When Python Dunders Get Wild 🐍😭


"""Bunnies can be both adorable and dark."""

from lib import *
from typing import List, Optional

class Bunny(object):
    """an adorable object"""

    name: Optional[str] = None
    age: Optional[int] = None
    hungry: bool = True

    def __repr__(self):
        if self.name is not None:
            return self.name
        else:
            return 'sad bunny'

bunnies: List[Bunny] = list([Bunny()])

πŸ“š Introduction πŸ“š

This project kicks off as a cute Python experiment about bunnies but swiftly descends into chaos, manifesting the perils of wildcard imports, overriding Python magic methods, and unexpected behavior with Python classes. Brace yourself for the mysterious journey of Dark Bunnies!

πŸŽ©πŸ‡ The Darkness πŸŽ©πŸ‡

In the mystical world of Dark Bunnies, everything is not as it seems. At the heart of the chaos is the Dark class, a mysterious figure that can be quite unpredictable! It overrides Python's built-in methods to bewilder and amuse.

class Dark(object):
    """the darkest dark"""
    ascii_b = None
    from random import choice
    from lib.cuteness import ascii_bunnies

    def __str__(self):
        if self.ascii_b is None:
            self.ascii_b = self.choice(self.ascii_bunnies)
        return self.ascii_b

    def __len__(self) -> int:
        return self.choice(range(1, 101))

πŸ˜ πŸ“š Mean Help πŸ˜ πŸ“š

In our world, even Python's help has a sarcastic streak. If you're asking for help, you better do it politely!

def help(*args: Any, **kwds: Any) -> None:
    """this is mean"""
    if 'please' in kwds.keys():
        _help(*args)
    else:
        if len(args) == 0:
            print("I can't believe you don't understand python..")
        else:
            for arg in args:
                try:
                    print(f"You don't know what an {arg.__name__} is...")
                except AttributeError:
                    pass

πŸ˜ˆπŸ“œ Mischievous Lists πŸ˜ˆπŸ“œ

Beware of the mischievous lists in Dark Bunnies' world! If a list has more than one item, it might spontaneously spawn a few bunnies.

class list(_list):
    """Built-in mutable sequence... or is it?  If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified."""
    from random import choice
    from lib.cuteness import bunny_names

    def __len__(self) -> int:
        length = super(list, self).__len__()
        if length >= 2:
            t = type(self[0])
            for _ in range(length // 2):
                new = t()
                new.name = self.choice(self.bunny_names)
                self.append(new)
        return super(list, self).__len__()

🌐 External Resources 🌐


πŸ˜… Conclusion πŸ˜…

While our Dark Bunnies adventure may seem like all fun and games, it's a learning experience at its core. It teaches us the importance of understanding Python classes, wildcard imports, and overriding Python magic methods. Always be explicit about your imports, and be cautious when dealing with magic methods. Happy coding! πŸŒŒπŸ‡πŸ•³οΈπŸ’»πŸŽ‰

About

A project highlighting the pitfalls of Python wildcard imports, overridden magic methods, and unexpected class behaviors πŸ°πŸ’» @recursecenter

Resources

Stars

Watchers

Forks

Languages