|
| 1 | +import pdb |
1 | 2 | from copy import copy |
2 | 3 | from json import JSONDecoder |
3 | 4 | from typing import Union, Any, List, Optional, Type, Callable, Dict |
4 | 5 | from pprint import pformat |
| 6 | +import textwrap |
5 | 7 |
|
6 | 8 | import yaml |
7 | 9 | from deprecated.classic import deprecated |
|
11 | 13 | from yaml.constructor import ConstructorError |
12 | 14 |
|
13 | 15 | from linkml_runtime.utils.context_utils import CONTEXTS_PARAM_TYPE, merge_contexts |
14 | | -from linkml_runtime.utils.formatutils import is_empty, remove_empty_items |
| 16 | +from linkml_runtime.utils.formatutils import is_empty, remove_empty_items, is_list, is_dict, items |
15 | 17 |
|
16 | 18 | YAMLObjTypes = Union[JsonObjTypes, "YAMLRoot"] |
17 | 19 |
|
@@ -278,10 +280,20 @@ def MissingRequiredField(self, field_name: str) -> None: |
278 | 280 | """ Generic loader error handler """ |
279 | 281 | raise ValueError(f"{field_name} must be supplied") |
280 | 282 |
|
| 283 | + def __repr__(self): |
| 284 | + """Only reformat 1-layer deep to preserve __repr__ of child objects""" |
| 285 | + res = {} |
| 286 | + for key, val in items(self): |
| 287 | + if val == [] or val == {} or val is None: |
| 288 | + continue |
| 289 | + res[key] = val |
| 290 | + return self.__class__.__name__ + '(' + pformat(res, indent=2, |
| 291 | + compact=True) + ')' |
| 292 | + |
281 | 293 | def __str__(self): |
| 294 | + """Dump everything into a dict, recursively, stringifying it all""" |
282 | 295 | res = remove_empty_items(self) |
283 | | - return pformat(as_dict(res),indent=2,compact=True) |
284 | | - |
| 296 | + return self.__class__.__name__ + '(' + pformat(res, indent=2, compact=True) + ')' |
285 | 297 |
|
286 | 298 |
|
287 | 299 | def root_representer(dumper: yaml.Dumper, data: YAMLRoot): |
|
0 commit comments