Check two structures for equality, optionally of types and of values.
(structure1,
structure2,
check_values=False)
| 240 | |
| 241 | |
| 242 | def is_same_structure(structure1, |
| 243 | structure2, |
| 244 | check_values=False): |
| 245 | """Check two structures for equality, optionally of types and of values.""" |
| 246 | try: |
| 247 | nest.assert_same_structure(structure1, structure2, expand_composites=True) |
| 248 | except (ValueError, TypeError): |
| 249 | return False |
| 250 | if check_values: |
| 251 | flattened1 = nest.flatten(structure1, expand_composites=True) |
| 252 | flattened2 = nest.flatten(structure2, expand_composites=True) |
| 253 | # First check the types to avoid AttributeErrors. |
| 254 | if any(type(f1) != type(f2) for f1, f2 in zip(flattened1, flattened2)): |
| 255 | return False |
| 256 | return flattened1 == flattened2 |
| 257 | return True |
| 258 | |
| 259 | |
| 260 | def _parse_func_attrs(attributes): |
no test coverage detected