Last active
March 24, 2021 02:07
-
-
Save meksor/4ce07539fffba8be0712ae2b6a87d9e8 to your computer and use it in GitHub Desktop.
rofl.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dis | |
class BaseA(type): | |
def __init__(self, name, bases, attrs): | |
foo_bytecode = [i.opcode for i in dis.Bytecode(attrs["foo"])] | |
if not 125 in foo_bytecode: | |
raise Exception( | |
f"The foo function in class {name} must assign at least one variable." | |
) | |
class A(metaclass=BaseA): | |
def dooglederp(self): | |
print("doogle") | |
def foo(self): | |
self.dooglederp() | |
baz = "baz" | |
class B(metaclass=BaseA): | |
def foo(self): | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment