(val, index=None)
| 272 | return True |
| 273 | |
| 274 | def _validate_value(val, index=None): |
| 275 | # val is a Component |
| 276 | if isinstance(val, Component): |
| 277 | unserializable_items = [] |
| 278 | # pylint: disable=protected-access |
| 279 | for p, j in val._traverse_with_paths(): |
| 280 | # check each component value in the tree |
| 281 | if not _valid_child(j): |
| 282 | _raise_invalid(bad_val=j, outer_val=val, path=p, index=index) |
| 283 | |
| 284 | if not _can_serialize(j): |
| 285 | # collect unserializable items separately, so we can report |
| 286 | # only the deepest level, not all the parent components that |
| 287 | # are just unserializable because of their children. |
| 288 | unserializable_items = [ |
| 289 | i for i in unserializable_items if not p.startswith(i[0]) |
| 290 | ] |
| 291 | if unserializable_items: |
| 292 | # we already have something unserializable in a different |
| 293 | # branch - time to stop and fail |
| 294 | break |
| 295 | if all(not i[0].startswith(p) for i in unserializable_items): |
| 296 | unserializable_items.append((p, j)) |
| 297 | |
| 298 | # Children that are not of type Component or |
| 299 | # list/tuple not returned by traverse |
| 300 | child = getattr(j, "children", None) |
| 301 | if not isinstance(child, (tuple, MutableSequence)): |
| 302 | if child and not _can_serialize(child): |
| 303 | _raise_invalid( |
| 304 | bad_val=child, |
| 305 | outer_val=val, |
| 306 | path=p + "\n" + "[*] " + type(child).__name__, |
| 307 | index=index, |
| 308 | ) |
| 309 | if unserializable_items: |
| 310 | p, j = unserializable_items[0] |
| 311 | # just report the first one, even if there are multiple, |
| 312 | # as that's how all the other errors work |
| 313 | _raise_invalid(bad_val=j, outer_val=val, path=p, index=index) |
| 314 | |
| 315 | # Also check the child of val, as it will not be returned |
| 316 | child = getattr(val, "children", None) |
| 317 | if not isinstance(child, (tuple, MutableSequence)): |
| 318 | if child and not _can_serialize(val): |
| 319 | _raise_invalid( |
| 320 | bad_val=child, |
| 321 | outer_val=val, |
| 322 | path=type(child).__name__, |
| 323 | index=index, |
| 324 | ) |
| 325 | |
| 326 | if not _can_serialize(val): |
| 327 | _raise_invalid( |
| 328 | bad_val=val, |
| 329 | outer_val=type(val).__name__, |
| 330 | path="", |
| 331 | index=index, |
no test coverage detected
searching dependent graphs…