Skip to content

Commit ef019dd

Browse files
committed
merged from master
1 parent 3bc07bb commit ef019dd

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

pyat/at/lattice/elements.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from copy import copy, deepcopy
1313
from abc import ABC
1414
from collections.abc import Generator, Iterable
15-
from typing import Optional
15+
from typing import Any, Optional
1616

1717

1818
def _array(value, shape=(-1,), dtype=numpy.float64):
@@ -371,7 +371,7 @@ def deepcopy(self) -> Element:
371371
"""Return a deep copy of the element"""
372372
return deepcopy(self)
373373

374-
def items(self) -> Generator[tuple, None, None]:
374+
def items(self) -> Generator[tuple[str, Any], None, None]:
375375
"""Iterates through the data members"""
376376
for k, v in vars(self).items():
377377
yield k, v
@@ -454,8 +454,22 @@ def popattr(element, attr):
454454
return element_list
455455

456456
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
459473

460474
def merge(self, other) -> None:
461475
super().merge(other)

0 commit comments

Comments
 (0)