本文整理汇总了Python中reprlib.Repr方法的典型用法代码示例。如果您正苦于以下问题:Python reprlib.Repr方法的具体用法?Python reprlib.Repr怎么用?Python reprlib.Repr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reprlib
的用法示例。
在下文中一共展示了reprlib.Repr方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import Repr [as 别名]
def __init__(self: object, backoff: object, verbose: bool = False):
"""
Setup for SequentialBackoffLemmatizer
:param backoff: Next lemmatizer in backoff chain
:type verbose: bool
:param verbose: Flag to include which lemmatizer assigned in
a given tag in the return tuple
"""
SequentialBackoffTagger.__init__(self, backoff=None)
# Setup backoff chain
if backoff is None:
self._taggers = [self]
else:
self._taggers = [self] + backoff._taggers
self.VERBOSE = verbose
self.repr = reprlib.Repr()
self.repr.maxlist = 1
self.repr.maxdict = 1
示例2: __init__
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import Repr [as 别名]
def __init__(self: object, backoff: object, verbose: bool = False):
"""
Setup for SequentialBackoffLemmatizer
:param backoff: Next lemmatizer in backoff chain
:param verbose: Flag to include which lemmatizer assigned in a given tag in the return tuple
"""
SequentialBackoffTagger.__init__(self, backoff=None)
# Setup backoff chain
if backoff is None:
self._taggers = [self]
else:
self._taggers = [self] + backoff._taggers
self.VERBOSE = verbose
self.repr = reprlib.Repr()
self.repr.maxlist = 1
self.repr.maxdict = 1
示例3: test_repr
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import Repr [as 别名]
def test_repr(self) -> None:
a_repr = reprlib.Repr()
a_repr.maxlist = 3
@icontract.require(lambda x: len(x) < 10, a_repr=a_repr)
def some_func(x: List[int]) -> None:
pass
violation_error = None # type: Optional[icontract.ViolationError]
try:
some_func(x=list(range(10 * 1000)))
except icontract.ViolationError as err:
violation_error = err
self.assertIsNotNone(violation_error)
self.assertEqual("len(x) < 10:\n"
"len(x) was 10000\n"
"x was [0, 1, 2, ...]", tests.error.wo_mandatory_location(str(violation_error)))
示例4: repr
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import Repr [as 别名]
def repr(self, x):
return self._callhelper(reprlib.Repr.repr, self, x)
示例5: saferepr
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import Repr [as 别名]
def saferepr(obj, maxsize=240):
"""return a size-limited safe repr-string for the given object.
Failing __repr__ functions of user instances will be represented
with a short exception info and 'saferepr' generally takes
care to never raise exceptions itself. This function is a wrapper
around the Repr/reprlib functionality of the standard 2.6 lib.
"""
# review exception handling
srepr = SafeRepr()
srepr.maxstring = maxsize
srepr.maxsize = maxsize
srepr.maxother = 160
return srepr.repr(obj)
示例6: saferepr
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import Repr [as 别名]
def saferepr(obj: object, maxsize: int = 240) -> str:
"""return a size-limited safe repr-string for the given object.
Failing __repr__ functions of user instances will be represented
with a short exception info and 'saferepr' generally takes
care to never raise exceptions itself. This function is a wrapper
around the Repr/reprlib functionality of the standard 2.6 lib.
"""
return SafeRepr(maxsize).repr(obj)
示例7: __init__
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import Repr [as 别名]
def __init__(self, master, title, dict=None):
width = 0
height = 40
if dict:
height = 20*len(dict) # XXX 20 == observed height of Entry widget
self.master = master
self.title = title
import reprlib
self.repr = reprlib.Repr()
self.repr.maxstring = 60
self.repr.maxother = 60
self.frame = frame = Frame(master)
self.frame.pack(expand=1, fill="both")
self.label = Label(frame, text=title, borderwidth=2, relief="groove")
self.label.pack(fill="x")
self.vbar = vbar = Scrollbar(frame, name="vbar")
vbar.pack(side="right", fill="y")
self.canvas = canvas = Canvas(frame,
height=min(300, max(40, height)),
scrollregion=(0, 0, width, height))
canvas.pack(side="left", fill="both", expand=1)
vbar["command"] = canvas.yview
canvas["yscrollcommand"] = vbar.set
self.subframe = subframe = Frame(canvas)
self.sfid = canvas.create_window(0, 0, window=subframe, anchor="nw")
self.load_dict(dict)
示例8: __repr__
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import Repr [as 别名]
def __repr__(self):
reprer = reprlib.Repr()
reprer.maxstring = 100
reprer.maxother = 100
meshes_names = reprer.repr(self._meshes)
if self.name is not None:
return f"{self.__class__.__name__}({meshes_names}, name={self.name})"
else:
return f"{self.__class__.__name__}{meshes_names}"
示例9: __repr__
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import Repr [as 别名]
def __repr__(self):
reprer = reprlib.Repr()
reprer.maxstring = 90
reprer.maxother = 90
slice_name = reprer.repr(self._meshes[0])
if self.name is not None:
return f"{self.__class__.__name__}({slice_name}, name={self.name})"
else:
return f"{self.__class__.__name__}({slice_name})"
示例10: __init__
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import Repr [as 别名]
def __init__(self,
condition: Callable[..., Any],
description: Optional[str] = None,
a_repr: reprlib.Repr = icontract._globals.aRepr,
enabled: bool = __debug__,
error: Optional[Union[Callable[..., Exception], type]] = None) -> None:
"""
Initialize.
:param condition: precondition predicate
:param description: textual description of the precondition
:param a_repr: representation instance that defines how the values are represented
:param enabled:
The decorator is applied only if this argument is set.
Otherwise, the condition check is disabled and there is no run-time overhead.
The default is to always check the condition unless the interpreter runs in optimized mode (``-O`` or
``-OO``).
:param error:
if given as a callable, ``error`` is expected to accept a subset of function arguments
(*e.g.*, also including ``result`` for perconditions, only ``self`` for invariants *etc.*) and return
an exception. The ``error`` is called on contract violation and the resulting exception is raised.
Otherwise, it is expected to denote an Exception class which is instantiated with the violation message
and raised on contract violation.
"""
# pylint: disable=too-many-arguments
self.enabled = enabled
self._contract = None # type: Optional[Contract]
if not enabled:
return
location = None # type: Optional[str]
tb_stack = traceback.extract_stack(limit=2)[:1]
if len(tb_stack) > 0:
frame = tb_stack[0]
location = 'File {}, line {} in {}'.format(frame.filename, frame.lineno, frame.name)
self._contract = Contract(
condition=condition, description=description, a_repr=a_repr, error=error, location=location)
示例11: __init__
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import Repr [as 别名]
def __init__(self,
condition: Callable[..., bool],
description: Optional[str] = None,
a_repr: reprlib.Repr = icontract._globals.aRepr,
error: Optional[Union[Callable[..., Exception], type]] = None,
location: Optional[str] = None) -> None:
"""
Initialize.
:param condition: condition predicate
:param description: textual description of the contract
:param a_repr: representation instance that defines how the values are represented
:param error:
if given as a callable, ``error`` is expected to accept a subset of function arguments
(*e.g.*, also including ``result`` for perconditions, only ``self`` for invariants *etc.*) and return
an exception. The ``error`` is called on contract violation and the resulting exception is raised.
Otherwise, it is expected to denote an Exception class which is instantiated with the violation message
and raised on contract violation.
:param location: indicate where the contract was defined (*e.g.*, path and line number)
"""
# pylint: disable=too-many-arguments
self.condition = condition
signature = inspect.signature(condition)
# All argument names of the condition
self.condition_args = list(signature.parameters.keys()) # type: List[str]
self.condition_arg_set = set(self.condition_args) # type: Set[str]
# Names of the mandatory arguments of the condition
self.mandatory_args = [
name for name, param in signature.parameters.items() if param.default == inspect.Parameter.empty
]
self.description = description
self._a_repr = a_repr
self.error = error
self.error_args = None # type: Optional[List[str]]
self.error_arg_set = None # type: Optional[Set[str]]
if error is not None and (inspect.isfunction(error) or inspect.ismethod(error)):
self.error_args = list(inspect.signature(error).parameters.keys())
self.error_arg_set = set(self.error_args)
self.location = location