Přejít k hlavnímu obsahu
🔒 Režim náhledu. Prvních patnáct lekcí Foundations je zdarma; tato je Pro. Spusťte 7denní trial pro odemčení editoru, AI nápověd a zbytku kurzu. Karta vyžadována, zrušte kdykoli v Dashboard.Spustit 7denní trial →
← KurzySenior Deep-DivesModul 1 · Concurrency & Async InternalsMetatřídypredict5 / 161
+100 XP
Úkol🌐 shown in EN
📝 **Task:** Predict the exact output. \`Meta.__new__\` prints \`meta_new:<name>\` as each class is built. \`Base.__init_subclass__\` prints \`init_sub:<name>\` and appends to \`registry\`. Two questions: (1) Does \`init_sub\` fire when \`Base\` itself is created? (2) Inside \`Meta.__new__\` — does \`print\` run before or after \`super().__new__\` builds the class? 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Předpověz výstup

Přečti kód pozorně

class Meta(type):
    def __new__(mcs, name, bases, ns):
        print(f"meta_new:{name}")
        return super().__new__(mcs, name, bases, ns)


class Base(metaclass=Meta):
    registry = []
    def __init_subclass__(cls, **kwargs):
        print(f"init_sub:{cls.__name__}")
        Base.registry.append(cls.__name__)


class A(Base):
    pass


class B(Base):
    pass


print(Base.registry)

Co program vypíše? Napiš sem: