Skip to content

Instantly share code, notes, and snippets.

@grantwwu
grantwwu / Can't log info inside metaclass?
Last active July 3, 2017 20:19
Why doesn't LOG.info work?
import logging
LOG = logging.getLogger(__name__)
LOG.setLevel(logging.INFO)
class foo(type):
def __new__(cls, name, bases, attrs):
LOG.warning("Warning working")
LOG.warning(LOG.isEnabledFor(logging.INFO))
LOG.info("Info working")
@grantwwu
grantwwu / metaclass_sigh.py
Created July 3, 2017 19:31
Metaclasses are hard
class foo(type):
def __new__(cls, name, bases, attrs):
raise Exception(str(attrs))
class bar(metaclass=foo):
var = 3
var2 = 4
@grantwwu
grantwwu / metaclass.py
Last active May 26, 2017 19:56
attr clarification
#!/usr/bin/env python3
class TestMeta(type):
def __new__(cls, names, bases, attrs):
print(attrs)
return super().__new__(cls, names, bases, attrs)
class Mixin(object):
def mixin_mrowr():
print("Miao")