summaryrefslogtreecommitdiff
path: root/python-cheap-repr.spec
blob: f9a350346f311fa716bba56ac9dd08580de2c8be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
%global _empty_manifest_terminate_build 0
Name:		python-cheap-repr
Version:	0.5.1
Release:	1
Summary:	Better version of repr/reprlib for short, cheap string representations.
License:	MIT
URL:		https://github.com/alexmojaki/cheap_repr
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/a2/5e/db3a56b40a396fc666d6a6a5dff8edfe067b6789c3745189654547d8c9da/cheap_repr-0.5.1.tar.gz
BuildArch:	noarch

Requires:	python3-qualname
Requires:	python3-pytest
Requires:	python3-Django
Requires:	python3-pandas
Requires:	python3-numpy
Requires:	python3-chainmap
Requires:	python3-Django
Requires:	python3-pandas
Requires:	python3-numpy
Requires:	python3-Django
Requires:	python3-pandas
Requires:	python3-numpy

%description
[![Build Status](https://github.com/alexmojaki/cheap_repr/workflows/Tests/badge.svg?branch=master)](https://github.com/alexmojaki/cheap_repr/actions) [![Coverage Status](https://coveralls.io/repos/github/alexmojaki/cheap_repr/badge.svg?branch=master)](https://coveralls.io/github/alexmojaki/cheap_repr?branch=master) [![Supports Python versions 2.7 and 3.4+, including PyPy](https://img.shields.io/pypi/pyversions/cheap_repr.svg)](https://pypi.python.org/pypi/cheap_repr) [![Join the chat at https://gitter.im/cheap_repr/Lobby](https://badges.gitter.im/cheap_repr/Lobby.svg)](https://gitter.im/cheap_repr/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
This library provides short, fast, configurable string representations, and an easy API for registering your own. It's an improvement of the standard library module `reprlib` (`repr` in Python 2).
Just use the `cheap_repr` function instead of `repr`:
```python
>>> from cheap_repr import cheap_repr
>>> cheap_repr(list(range(100)))
'[0, 1, 2, ..., 97, 98, 99]'
```
`cheap_repr` knows how to handle many different types out of the box. You can register a function for any type, and pull requests to make these part of the library are welcome. If it doesn't know how to handle a particular type, the default `repr()` is used, possibly truncated:
```python
>>> class MyClass(object):
>>> c = MyClass(list(range(20)))
>>> c
MyClass([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])
>>> cheap_repr(c)
'MyClass([0, 1, 2, 3, 4, 5, 6... 13, 14, 15, 16, 17, 18, 19])'
```
## Suppression of long reprs
`cheap_repr` is meant to prevent slow, expensive computations of string representations. So if it finds that a particular class can potentially produce very long representations, the class will be *suppressed*, meaning that in future the  `__repr__` won't be calculated at all:
```python
>>> cheap_repr(MyClass(list(range(1000))))
'MyClass([0, 1, 2, 3, 4, 5, 6...94, 995, 996, 997, 998, 999])'
>>> cheap_repr(MyClass(list(range(1000))))
'<MyClass instance at 0x1034de7f0 (repr suppressed)>'
```
`cheap_repr.suppression_threshold` refers to the attribute on the function itself, not the module. By default it's 300, meaning that a `repr` longer than 300 characters will trigger the suppression.
## Registering your own repr function
For example:
```python
>>> from cheap_repr import register_repr
>>> @register_repr(MyClass)
>>> cheap_repr(MyClass(list(range(1000))))
'MyClass([0, 1, 2, 3, 4, 5, ...])'
```
In general, write a function that takes two arguments `(x, helper)` and decorate it with `register_repr(cls)`. Then `cheap_repr(x)` where `isinstance(x, cls)` will dispatch to that function, unless there is also a registered function for a subclass which `x` is also an instance of. More precisely, the function corresponding to the first class in the MRO will be used. This is in contrast to the standard library module `reprlib`, which cannot handle subclasses that aren't explicitly 'registered', or classes with the same name.
The `helper` argument is an object with a couple of useful attributes and methods:
- `repr_iterable(iterable, left, right, end=False, length=None)` produces a comma-separated representation of `iterable`, automatically handling nesting and iterables that are too long, surrounded by `left` and `right`. The number of items is limited to `func.maxparts` (see the configuration section below).
   Set `end=True` to include items from both the beginning and end, possibly leaving out items
 in the middle. Only do this if `iterable` supports efficient slicing at the end, e.g. `iterable[-3:]`.
    Provide the `length` parameter if `len(iterable)` doesn't work. Usually this is not needed.
- `truncate(string)` returns a version of `string` at most `func.maxparts` characters long, with the middle replaced by `...` if necessary.
- `level` indicates how much nesting is still allowed in the result. If it's 0, return something minimal such as `[...]` to indicate that the original object is too deep to show all its contents. Otherwise, if you use `cheap_repr` on several items inside `x`, pass `helper.level - 1` as the second argument, e.g. `', '.join(cheap_repr(item, helper.level - 1) for item in x)`.
## Exceptions in repr functions
If an exception occurs in `cheap_repr`, whether from a registered repr function or the usual `__repr__`, the exception will be caught and the cheap repr of the class will be suppressed:
```python
>>> @register_repr(MyClass)
>>> cheap_repr(MyClass([]))
'<MyClass instance at 0x10f44ec50 (exception in repr)>'
>>> cheap_repr(MyClass([1, 2, 3]))
'<MyClass instance at 0x10f44ecc0 (repr suppressed)>'
```
If you would prefer exceptions to bubble up normally, you can:
1. Set `cheap_repr.raise_exceptions = True` to globally make all exceptions bubble up.
2. To bubble exceptions from the `__repr__` of a class, call `raise_exceptions_from_default_repr()`.
3. Set `repr_my_class.raise_exceptions = True` (substituting your own registered repr function) to make exceptions bubble from that function. The way to find the relevant function is in the next section.
## Configuration:
### Configuration for specific functions
To configure a specific function, you set attributes on that function. To find the function corresponding to a class, use `find_repr_function`:
```python
>>> from cheap_repr import find_repr_function
>>> find_repr_function(MyClass)
<function repr_my_class at 0x10f43d8c8>
```
For most functions, there are two attributes available to configure, but contributors and library writers are encouraged to add arbitrary attributes for their own functions. The first attribute is `raise_exceptions`, described in the previous section.
### maxparts
The other configurable attribute is `maxparts`. All registered repr functions have this attribute. It determines the maximum number of 'parts' (e.g. list elements or string characters, the meaning depends on the function) from the input that the output can display without truncation. The default value is 6. The decorator `@maxparts(n)` conveniently sets the attribute to make writing your own registered functions nicer. For example:
```python
>>> from cheap_repr import maxparts
>>> @register_repr(MyClass)
>>> cheap_repr(MyClass([1, 2, 3, 4]))
'MyClass([1, 2, ...])'
>>> find_repr_function(MyClass).maxparts = 3
>>> cheap_repr(MyClass([1, 2, 3, 4]))
'MyClass([1, 2, 3, ...])'
```
### pandas
The functions for `DataFrame`s and `Series` from the `pandas` library don't use `maxparts`.
For the `DataFrame` function there's `max_rows` and `max_cols`. For the `Series` function there's just `max_rows`.
### level and max_level
`cheap_repr` takes an optional argument `level` which controls the display of nested objects. Typically this decreases through recursive calls, and when it's 0, the contents of the object aren't shown. See 'Registering your own repr function' for more details. This means you can change the amount of nested data in the output of `cheap_repr` by changing the `level` argument. The default value is `cheap_repr.max_level`, which is initially 3. This means that changing `cheap_repr.max_level` will effectively change the `level` argument whenever it isn't explicitly specified.
### Global configuration
These things that can be configured globally:
1. `cheap_repr.suppression_threshold`, discussed in the 'Suppression of long reprs' section.
2. The handling of exceptions, discussed in the 'Exceptions in repr functions' section, which can be changed by setting `cheap_repr.raise_exceptions = True` or calling `raise_exceptions_from_default_repr()`.
3. `cheap_repr.max_level`, discussed above.
## Other miscellaneous functions
`basic_repr(x)` returns a string that looks like the default `object.__repr__`. This is handy if you don't want to write your own repr function to register. Simply register this function instead, e.g.
```python
>>> from cheap_repr import basic_repr
>>> register_repr(MyClass)(basic_repr)
>>> cheap_repr(MyClass([1, 2, 3, 4]))
'<MyClass instance at 0x10f39dda0>'
```
`normal_repr(x)` returns `repr(x)` - register it with a class to indicate that its own `__repr__` method is already fine. This prevents it from being supressed when its output is a bit long.
`try_register_repr` is handy when you want to register a repr function for a class that may not exist, e.g. if the class is in a third party package that may not be installed. See the docstring for more details.

%package -n python3-cheap-repr
Summary:	Better version of repr/reprlib for short, cheap string representations.
Provides:	python-cheap-repr
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-cheap-repr
[![Build Status](https://github.com/alexmojaki/cheap_repr/workflows/Tests/badge.svg?branch=master)](https://github.com/alexmojaki/cheap_repr/actions) [![Coverage Status](https://coveralls.io/repos/github/alexmojaki/cheap_repr/badge.svg?branch=master)](https://coveralls.io/github/alexmojaki/cheap_repr?branch=master) [![Supports Python versions 2.7 and 3.4+, including PyPy](https://img.shields.io/pypi/pyversions/cheap_repr.svg)](https://pypi.python.org/pypi/cheap_repr) [![Join the chat at https://gitter.im/cheap_repr/Lobby](https://badges.gitter.im/cheap_repr/Lobby.svg)](https://gitter.im/cheap_repr/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
This library provides short, fast, configurable string representations, and an easy API for registering your own. It's an improvement of the standard library module `reprlib` (`repr` in Python 2).
Just use the `cheap_repr` function instead of `repr`:
```python
>>> from cheap_repr import cheap_repr
>>> cheap_repr(list(range(100)))
'[0, 1, 2, ..., 97, 98, 99]'
```
`cheap_repr` knows how to handle many different types out of the box. You can register a function for any type, and pull requests to make these part of the library are welcome. If it doesn't know how to handle a particular type, the default `repr()` is used, possibly truncated:
```python
>>> class MyClass(object):
>>> c = MyClass(list(range(20)))
>>> c
MyClass([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])
>>> cheap_repr(c)
'MyClass([0, 1, 2, 3, 4, 5, 6... 13, 14, 15, 16, 17, 18, 19])'
```
## Suppression of long reprs
`cheap_repr` is meant to prevent slow, expensive computations of string representations. So if it finds that a particular class can potentially produce very long representations, the class will be *suppressed*, meaning that in future the  `__repr__` won't be calculated at all:
```python
>>> cheap_repr(MyClass(list(range(1000))))
'MyClass([0, 1, 2, 3, 4, 5, 6...94, 995, 996, 997, 998, 999])'
>>> cheap_repr(MyClass(list(range(1000))))
'<MyClass instance at 0x1034de7f0 (repr suppressed)>'
```
`cheap_repr.suppression_threshold` refers to the attribute on the function itself, not the module. By default it's 300, meaning that a `repr` longer than 300 characters will trigger the suppression.
## Registering your own repr function
For example:
```python
>>> from cheap_repr import register_repr
>>> @register_repr(MyClass)
>>> cheap_repr(MyClass(list(range(1000))))
'MyClass([0, 1, 2, 3, 4, 5, ...])'
```
In general, write a function that takes two arguments `(x, helper)` and decorate it with `register_repr(cls)`. Then `cheap_repr(x)` where `isinstance(x, cls)` will dispatch to that function, unless there is also a registered function for a subclass which `x` is also an instance of. More precisely, the function corresponding to the first class in the MRO will be used. This is in contrast to the standard library module `reprlib`, which cannot handle subclasses that aren't explicitly 'registered', or classes with the same name.
The `helper` argument is an object with a couple of useful attributes and methods:
- `repr_iterable(iterable, left, right, end=False, length=None)` produces a comma-separated representation of `iterable`, automatically handling nesting and iterables that are too long, surrounded by `left` and `right`. The number of items is limited to `func.maxparts` (see the configuration section below).
   Set `end=True` to include items from both the beginning and end, possibly leaving out items
 in the middle. Only do this if `iterable` supports efficient slicing at the end, e.g. `iterable[-3:]`.
    Provide the `length` parameter if `len(iterable)` doesn't work. Usually this is not needed.
- `truncate(string)` returns a version of `string` at most `func.maxparts` characters long, with the middle replaced by `...` if necessary.
- `level` indicates how much nesting is still allowed in the result. If it's 0, return something minimal such as `[...]` to indicate that the original object is too deep to show all its contents. Otherwise, if you use `cheap_repr` on several items inside `x`, pass `helper.level - 1` as the second argument, e.g. `', '.join(cheap_repr(item, helper.level - 1) for item in x)`.
## Exceptions in repr functions
If an exception occurs in `cheap_repr`, whether from a registered repr function or the usual `__repr__`, the exception will be caught and the cheap repr of the class will be suppressed:
```python
>>> @register_repr(MyClass)
>>> cheap_repr(MyClass([]))
'<MyClass instance at 0x10f44ec50 (exception in repr)>'
>>> cheap_repr(MyClass([1, 2, 3]))
'<MyClass instance at 0x10f44ecc0 (repr suppressed)>'
```
If you would prefer exceptions to bubble up normally, you can:
1. Set `cheap_repr.raise_exceptions = True` to globally make all exceptions bubble up.
2. To bubble exceptions from the `__repr__` of a class, call `raise_exceptions_from_default_repr()`.
3. Set `repr_my_class.raise_exceptions = True` (substituting your own registered repr function) to make exceptions bubble from that function. The way to find the relevant function is in the next section.
## Configuration:
### Configuration for specific functions
To configure a specific function, you set attributes on that function. To find the function corresponding to a class, use `find_repr_function`:
```python
>>> from cheap_repr import find_repr_function
>>> find_repr_function(MyClass)
<function repr_my_class at 0x10f43d8c8>
```
For most functions, there are two attributes available to configure, but contributors and library writers are encouraged to add arbitrary attributes for their own functions. The first attribute is `raise_exceptions`, described in the previous section.
### maxparts
The other configurable attribute is `maxparts`. All registered repr functions have this attribute. It determines the maximum number of 'parts' (e.g. list elements or string characters, the meaning depends on the function) from the input that the output can display without truncation. The default value is 6. The decorator `@maxparts(n)` conveniently sets the attribute to make writing your own registered functions nicer. For example:
```python
>>> from cheap_repr import maxparts
>>> @register_repr(MyClass)
>>> cheap_repr(MyClass([1, 2, 3, 4]))
'MyClass([1, 2, ...])'
>>> find_repr_function(MyClass).maxparts = 3
>>> cheap_repr(MyClass([1, 2, 3, 4]))
'MyClass([1, 2, 3, ...])'
```
### pandas
The functions for `DataFrame`s and `Series` from the `pandas` library don't use `maxparts`.
For the `DataFrame` function there's `max_rows` and `max_cols`. For the `Series` function there's just `max_rows`.
### level and max_level
`cheap_repr` takes an optional argument `level` which controls the display of nested objects. Typically this decreases through recursive calls, and when it's 0, the contents of the object aren't shown. See 'Registering your own repr function' for more details. This means you can change the amount of nested data in the output of `cheap_repr` by changing the `level` argument. The default value is `cheap_repr.max_level`, which is initially 3. This means that changing `cheap_repr.max_level` will effectively change the `level` argument whenever it isn't explicitly specified.
### Global configuration
These things that can be configured globally:
1. `cheap_repr.suppression_threshold`, discussed in the 'Suppression of long reprs' section.
2. The handling of exceptions, discussed in the 'Exceptions in repr functions' section, which can be changed by setting `cheap_repr.raise_exceptions = True` or calling `raise_exceptions_from_default_repr()`.
3. `cheap_repr.max_level`, discussed above.
## Other miscellaneous functions
`basic_repr(x)` returns a string that looks like the default `object.__repr__`. This is handy if you don't want to write your own repr function to register. Simply register this function instead, e.g.
```python
>>> from cheap_repr import basic_repr
>>> register_repr(MyClass)(basic_repr)
>>> cheap_repr(MyClass([1, 2, 3, 4]))
'<MyClass instance at 0x10f39dda0>'
```
`normal_repr(x)` returns `repr(x)` - register it with a class to indicate that its own `__repr__` method is already fine. This prevents it from being supressed when its output is a bit long.
`try_register_repr` is handy when you want to register a repr function for a class that may not exist, e.g. if the class is in a third party package that may not be installed. See the docstring for more details.

%package help
Summary:	Development documents and examples for cheap-repr
Provides:	python3-cheap-repr-doc
%description help
[![Build Status](https://github.com/alexmojaki/cheap_repr/workflows/Tests/badge.svg?branch=master)](https://github.com/alexmojaki/cheap_repr/actions) [![Coverage Status](https://coveralls.io/repos/github/alexmojaki/cheap_repr/badge.svg?branch=master)](https://coveralls.io/github/alexmojaki/cheap_repr?branch=master) [![Supports Python versions 2.7 and 3.4+, including PyPy](https://img.shields.io/pypi/pyversions/cheap_repr.svg)](https://pypi.python.org/pypi/cheap_repr) [![Join the chat at https://gitter.im/cheap_repr/Lobby](https://badges.gitter.im/cheap_repr/Lobby.svg)](https://gitter.im/cheap_repr/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
This library provides short, fast, configurable string representations, and an easy API for registering your own. It's an improvement of the standard library module `reprlib` (`repr` in Python 2).
Just use the `cheap_repr` function instead of `repr`:
```python
>>> from cheap_repr import cheap_repr
>>> cheap_repr(list(range(100)))
'[0, 1, 2, ..., 97, 98, 99]'
```
`cheap_repr` knows how to handle many different types out of the box. You can register a function for any type, and pull requests to make these part of the library are welcome. If it doesn't know how to handle a particular type, the default `repr()` is used, possibly truncated:
```python
>>> class MyClass(object):
>>> c = MyClass(list(range(20)))
>>> c
MyClass([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])
>>> cheap_repr(c)
'MyClass([0, 1, 2, 3, 4, 5, 6... 13, 14, 15, 16, 17, 18, 19])'
```
## Suppression of long reprs
`cheap_repr` is meant to prevent slow, expensive computations of string representations. So if it finds that a particular class can potentially produce very long representations, the class will be *suppressed*, meaning that in future the  `__repr__` won't be calculated at all:
```python
>>> cheap_repr(MyClass(list(range(1000))))
'MyClass([0, 1, 2, 3, 4, 5, 6...94, 995, 996, 997, 998, 999])'
>>> cheap_repr(MyClass(list(range(1000))))
'<MyClass instance at 0x1034de7f0 (repr suppressed)>'
```
`cheap_repr.suppression_threshold` refers to the attribute on the function itself, not the module. By default it's 300, meaning that a `repr` longer than 300 characters will trigger the suppression.
## Registering your own repr function
For example:
```python
>>> from cheap_repr import register_repr
>>> @register_repr(MyClass)
>>> cheap_repr(MyClass(list(range(1000))))
'MyClass([0, 1, 2, 3, 4, 5, ...])'
```
In general, write a function that takes two arguments `(x, helper)` and decorate it with `register_repr(cls)`. Then `cheap_repr(x)` where `isinstance(x, cls)` will dispatch to that function, unless there is also a registered function for a subclass which `x` is also an instance of. More precisely, the function corresponding to the first class in the MRO will be used. This is in contrast to the standard library module `reprlib`, which cannot handle subclasses that aren't explicitly 'registered', or classes with the same name.
The `helper` argument is an object with a couple of useful attributes and methods:
- `repr_iterable(iterable, left, right, end=False, length=None)` produces a comma-separated representation of `iterable`, automatically handling nesting and iterables that are too long, surrounded by `left` and `right`. The number of items is limited to `func.maxparts` (see the configuration section below).
   Set `end=True` to include items from both the beginning and end, possibly leaving out items
 in the middle. Only do this if `iterable` supports efficient slicing at the end, e.g. `iterable[-3:]`.
    Provide the `length` parameter if `len(iterable)` doesn't work. Usually this is not needed.
- `truncate(string)` returns a version of `string` at most `func.maxparts` characters long, with the middle replaced by `...` if necessary.
- `level` indicates how much nesting is still allowed in the result. If it's 0, return something minimal such as `[...]` to indicate that the original object is too deep to show all its contents. Otherwise, if you use `cheap_repr` on several items inside `x`, pass `helper.level - 1` as the second argument, e.g. `', '.join(cheap_repr(item, helper.level - 1) for item in x)`.
## Exceptions in repr functions
If an exception occurs in `cheap_repr`, whether from a registered repr function or the usual `__repr__`, the exception will be caught and the cheap repr of the class will be suppressed:
```python
>>> @register_repr(MyClass)
>>> cheap_repr(MyClass([]))
'<MyClass instance at 0x10f44ec50 (exception in repr)>'
>>> cheap_repr(MyClass([1, 2, 3]))
'<MyClass instance at 0x10f44ecc0 (repr suppressed)>'
```
If you would prefer exceptions to bubble up normally, you can:
1. Set `cheap_repr.raise_exceptions = True` to globally make all exceptions bubble up.
2. To bubble exceptions from the `__repr__` of a class, call `raise_exceptions_from_default_repr()`.
3. Set `repr_my_class.raise_exceptions = True` (substituting your own registered repr function) to make exceptions bubble from that function. The way to find the relevant function is in the next section.
## Configuration:
### Configuration for specific functions
To configure a specific function, you set attributes on that function. To find the function corresponding to a class, use `find_repr_function`:
```python
>>> from cheap_repr import find_repr_function
>>> find_repr_function(MyClass)
<function repr_my_class at 0x10f43d8c8>
```
For most functions, there are two attributes available to configure, but contributors and library writers are encouraged to add arbitrary attributes for their own functions. The first attribute is `raise_exceptions`, described in the previous section.
### maxparts
The other configurable attribute is `maxparts`. All registered repr functions have this attribute. It determines the maximum number of 'parts' (e.g. list elements or string characters, the meaning depends on the function) from the input that the output can display without truncation. The default value is 6. The decorator `@maxparts(n)` conveniently sets the attribute to make writing your own registered functions nicer. For example:
```python
>>> from cheap_repr import maxparts
>>> @register_repr(MyClass)
>>> cheap_repr(MyClass([1, 2, 3, 4]))
'MyClass([1, 2, ...])'
>>> find_repr_function(MyClass).maxparts = 3
>>> cheap_repr(MyClass([1, 2, 3, 4]))
'MyClass([1, 2, 3, ...])'
```
### pandas
The functions for `DataFrame`s and `Series` from the `pandas` library don't use `maxparts`.
For the `DataFrame` function there's `max_rows` and `max_cols`. For the `Series` function there's just `max_rows`.
### level and max_level
`cheap_repr` takes an optional argument `level` which controls the display of nested objects. Typically this decreases through recursive calls, and when it's 0, the contents of the object aren't shown. See 'Registering your own repr function' for more details. This means you can change the amount of nested data in the output of `cheap_repr` by changing the `level` argument. The default value is `cheap_repr.max_level`, which is initially 3. This means that changing `cheap_repr.max_level` will effectively change the `level` argument whenever it isn't explicitly specified.
### Global configuration
These things that can be configured globally:
1. `cheap_repr.suppression_threshold`, discussed in the 'Suppression of long reprs' section.
2. The handling of exceptions, discussed in the 'Exceptions in repr functions' section, which can be changed by setting `cheap_repr.raise_exceptions = True` or calling `raise_exceptions_from_default_repr()`.
3. `cheap_repr.max_level`, discussed above.
## Other miscellaneous functions
`basic_repr(x)` returns a string that looks like the default `object.__repr__`. This is handy if you don't want to write your own repr function to register. Simply register this function instead, e.g.
```python
>>> from cheap_repr import basic_repr
>>> register_repr(MyClass)(basic_repr)
>>> cheap_repr(MyClass([1, 2, 3, 4]))
'<MyClass instance at 0x10f39dda0>'
```
`normal_repr(x)` returns `repr(x)` - register it with a class to indicate that its own `__repr__` method is already fine. This prevents it from being supressed when its output is a bit long.
`try_register_repr` is handy when you want to register a repr function for a class that may not exist, e.g. if the class is in a third party package that may not be installed. See the docstring for more details.

%prep
%autosetup -n cheap-repr-0.5.1

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-cheap-repr -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Tue Apr 11 2023 Python_Bot <Python_Bot@openeuler.org> - 0.5.1-1
- Package Spec generated