|
12 | 12 | from copy import copy, deepcopy
|
13 | 13 | from abc import ABC
|
14 | 14 | from collections.abc import Generator, Iterable
|
15 |
| -from typing import Optional |
| 15 | +from typing import Any, Optional |
16 | 16 |
|
17 | 17 |
|
18 | 18 | def _array(value, shape=(-1,), dtype=numpy.float64):
|
@@ -371,7 +371,7 @@ def deepcopy(self) -> Element:
|
371 | 371 | """Return a deep copy of the element"""
|
372 | 372 | return deepcopy(self)
|
373 | 373 |
|
374 |
| - def items(self) -> Generator[tuple, None, None]: |
| 374 | + def items(self) -> Generator[tuple[str, Any], None, None]: |
375 | 375 | """Iterates through the data members"""
|
376 | 376 | for k, v in vars(self).items():
|
377 | 377 | yield k, v
|
@@ -454,8 +454,22 @@ def popattr(element, attr):
|
454 | 454 | return element_list
|
455 | 455 |
|
456 | 456 | def is_compatible(self, other) -> bool:
|
457 |
| - return type(other) is type(self) and \ |
458 |
| - self.PassMethod == other.PassMethod |
| 457 | + def compatible_field(fieldname): |
| 458 | + f1 = getattr(self, fieldname, None) |
| 459 | + f2 = getattr(other, fieldname, None) |
| 460 | + if f1 is None and f2 is None: # no such field |
| 461 | + return True |
| 462 | + elif f1 is None or f2 is None: # only one |
| 463 | + return False |
| 464 | + else: # both |
| 465 | + return numpy.all(f1 == f2) |
| 466 | + |
| 467 | + if not (type(other) is type(self) and self.PassMethod == other.PassMethod): |
| 468 | + return False |
| 469 | + for fname in ("RApertures", "EApertures"): |
| 470 | + if not compatible_field(fname): |
| 471 | + return False |
| 472 | + return True |
459 | 473 |
|
460 | 474 | def merge(self, other) -> None:
|
461 | 475 | super().merge(other)
|
|
0 commit comments