Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesSenior Deep-DivesModule 6 · FAANG-2026 deep dives__init_subclass__ — auto-registration without metaclassespredict116 / 161
+150 XP
Task
📝 **Task:** Predict the exact output. \`Plugin\` auto-registers its subclasses. \`TaggedPlugin\` reads a \`tag\` kwarg from each subclass declaration. Two subclasses of \`Plugin\` and one of \`TaggedPlugin\`. What does the registry contain, and what is \`A.tag\`? 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Predict the output

Read the code carefully

class Plugin:
    registry = {}

    def __init_subclass__(cls, **kwargs):
        super().__init_subclass__(**kwargs)
        Plugin.registry[cls.__name__] = cls


class ImageProcessor(Plugin):
    pass


class TextProcessor(Plugin):
    pass


print(sorted(Plugin.registry.keys()))
print(Plugin.registry["ImageProcessor"].__name__)


class TaggedPlugin:
    def __init_subclass__(cls, *, tag="unset", **kwargs):
        super().__init_subclass__(**kwargs)
        cls.tag = tag


class A(TaggedPlugin, tag="alpha"):
    pass


print(A.tag)

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…