本文整理匯總了Python中types.DictProxyType方法的典型用法代碼示例。如果您正苦於以下問題:Python types.DictProxyType方法的具體用法?Python types.DictProxyType怎麽用?Python types.DictProxyType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類types
的用法示例。
在下文中一共展示了types.DictProxyType方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __dir__
# 需要導入模塊: import types [as 別名]
# 或者: from types import DictProxyType [as 別名]
def __dir__(self):
def get_attrs(obj):
import types
if not hasattr(obj, '__dict__'):
return [] # slots only
if not isinstance(obj.__dict__, (dict, types.DictProxyType)):
raise TypeError("%s.__dict__ is not a dictionary"
"" % obj.__name__)
return obj.__dict__.keys()
def dir2(obj):
attrs = set()
if not hasattr(obj, '__bases__'):
# obj is an instance
if not hasattr(obj, '__class__'):
# slots
return sorted(get_attrs(obj))
klass = obj.__class__
attrs.update(get_attrs(klass))
else:
# obj is a class
klass = obj
for cls in klass.__bases__:
attrs.update(get_attrs(cls))
attrs.update(dir2(cls))
attrs.update(get_attrs(obj))
return list(attrs)
return dir2(self)
示例2: _is_unsupported_type
# 需要導入模塊: import types [as 別名]
# 或者: from types import DictProxyType [as 別名]
def _is_unsupported_type(obj):
return isinstance(obj, (types.ComplexType, types.TupleType, types.FunctionType, types.LambdaType,
types.GeneratorType, types.MethodType, types.UnboundMethodType, types.BuiltinFunctionType, types.BuiltinMethodType, types.FileType,
types.XRangeType, types.TracebackType, types.FrameType, types.DictProxyType, types.NotImplementedType, types.GetSetDescriptorType,
types.MemberDescriptorType))