虚空之鸭,万能的鸭鸭,无能的鸭鸭,随你怎么对待它,鸭鸭不反抗,鸭鸭不回答
https://github.com/mo-han/mo-han-toolbox/blob/master/lib_misc.py#L29
class VoidDuck:
"""a void, versatile, useless and quiet duck, called in any way, return nothing, raise nothing"""
def __init__(self, *args, **kwargs):
pass
def __getattr__(self, item):
return self
def __call__(self, *args, **kwargs):
return self
def __bool__(self):
return False
1
Ritter 2020-05-21 14:09:23 +08:00
???
|
3
no1xsyzy 2020-05-21 15:53:47 +08:00 1
vd = VoidDuck()
vd.__class__.__getattr__ = lambda self, key: None assert VoidDuck().item is None |