本文整理汇总了Python中reprlib.recursive_repr方法的典型用法代码示例。如果您正苦于以下问题:Python reprlib.recursive_repr方法的具体用法?Python reprlib.recursive_repr怎么用?Python reprlib.recursive_repr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reprlib
的用法示例。
在下文中一共展示了reprlib.recursive_repr方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setdefault
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import recursive_repr [as 别名]
def setdefault(self, key, default=None):
'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od'
if key in self:
return self[key]
self[key] = default
return default
#fixme, brython issue
#@_recursive_repr()
示例2: __bool__
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import recursive_repr [as 别名]
def __bool__(self):
return any(self.maps)
#fixme, brython
#@_recursive_repr()
示例3: ceil
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import recursive_repr [as 别名]
def ceil(x):
"""
Return the ceiling of x as an int.
This is the smallest integral value >= x.
"""
return int(oldceil(x))
########################################################################
### reprlib.recursive_repr decorator from Py3.4
########################################################################
示例4: recursive_repr
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import recursive_repr [as 别名]
def recursive_repr(fillvalue='...'):
'Decorator to make a repr function return fillvalue for a recursive call'
def decorating_function(user_function):
repr_running = set()
def wrapper(self):
key = id(self), get_ident()
if key in repr_running:
return fillvalue
repr_running.add(key)
try:
result = user_function(self)
finally:
repr_running.discard(key)
return result
# Can't use functools.wraps() here because of bootstrap issues
wrapper.__module__ = getattr(user_function, '__module__')
wrapper.__doc__ = getattr(user_function, '__doc__')
wrapper.__name__ = getattr(user_function, '__name__')
wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
return wrapper
return decorating_function
################################################################################
### OrderedDict
################################################################################
示例5: _recursive_repr
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import recursive_repr [as 别名]
def _recursive_repr(fillvalue='...'):
'''
Decorator to make a repr function return fillvalue for a recursive
call
'''
def decorating_function(user_function):
repr_running = set()
def wrapper(self):
key = id(self), get_ident()
if key in repr_running:
return fillvalue
repr_running.add(key)
try:
result = user_function(self)
finally:
repr_running.discard(key)
return result
# Can't use functools.wraps() here because of bootstrap issues
wrapper.__module__ = getattr(user_function, '__module__')
wrapper.__doc__ = getattr(user_function, '__doc__')
wrapper.__name__ = getattr(user_function, '__name__')
wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
return wrapper
return decorating_function