Python reprlib.Repr() Examples
The following are 17
code examples of reprlib.Repr().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
reprlib
, or try the search function
.
Example #1
Source File: backoff.py From cltk with MIT License | 6 votes |
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
Example #2
Source File: ensemble.py From cltk with MIT License | 6 votes |
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
Example #3
Source File: test_represent.py From icontract with MIT License | 6 votes |
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)))
Example #4
Source File: Debugger.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #5
Source File: symmetric.py From capytaine with GNU General Public License v3.0 | 5 votes |
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})"
Example #6
Source File: collections.py From capytaine with GNU General Public License v3.0 | 5 votes |
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}"
Example #7
Source File: Debugger.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #8
Source File: saferepr.py From python-netsurv with MIT License | 5 votes |
def repr(self, x): return self._callhelper(reprlib.Repr.repr, self, x)
Example #9
Source File: Debugger.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #10
Source File: saferepr.py From pytest with MIT License | 5 votes |
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)
Example #11
Source File: saferepr.py From python-netsurv with MIT License | 5 votes |
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)
Example #12
Source File: saferepr.py From python-netsurv with MIT License | 5 votes |
def repr(self, x): return self._callhelper(reprlib.Repr.repr, self, x)
Example #13
Source File: saferepr.py From python-netsurv with MIT License | 5 votes |
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)
Example #14
Source File: _decorators.py From icontract with MIT License | 4 votes |
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)
Example #15
Source File: _decorators.py From icontract with MIT License | 4 votes |
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: postcondition predicate :param description: textual description of the postcondition :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)
Example #16
Source File: _decorators.py From icontract with MIT License | 4 votes |
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 a class decorator to establish the invariant on all the public methods. :param condition: invariant predicate :param description: textual description of the invariant :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. :return: """ # 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) if self._contract.mandatory_args and self._contract.mandatory_args != ['self']: raise ValueError("Expected an invariant condition with at most an argument 'self', but got: {}".format( self._contract.condition_args))
Example #17
Source File: _types.py From icontract with MIT License | 4 votes |
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