Skip to content

Commit eab12a2

Browse files
committed
DOC: clarify docstring of Structure.extend
Also use more descriptive variable names. No change in code function.
1 parent a2c2ab7 commit eab12a2

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/diffpy/structure/structure.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -339,37 +339,36 @@ def insert(self, idx, a, copy=True):
339339

340340

341341
def extend(self, atoms, copy=None):
342-
"""Extend Structure with the specified sequence of atoms.
342+
"""Extend Structure with an iterable of atoms.
343343
344344
Update the `lattice` attribute of all added atoms.
345345
346346
Parameters
347347
----------
348348
atoms : iterable
349-
The `Atom` instances to be appended to this Structure.
349+
The `Atom` objects to be appended to this Structure.
350350
copy : bool, optional
351351
Flag for adding copies of Atom objects.
352-
Make copies when `True`, append `atoms` as are when ``False``.
353-
The default behavior is to make copies when `atoms` are
354-
of `Structure` type or if the new atoms introduce repeated
355-
instances.
352+
Make copies when `True`, append `atoms` unchanged when ``False``.
353+
The default behavior is to make copies when `atoms` are of
354+
`Structure` type or if new atoms introduce repeated objects.
356355
"""
357356
adups = (copymod.copy(a) for a in atoms)
358357
if copy is None:
359358
if isinstance(atoms, Structure):
360-
extatoms = adups
359+
newatoms = adups
361360
else:
362361
memo = set(id(a) for a in self)
363-
newatom = lambda a: (a if id(a) not in memo
364-
else copymod.copy(a))
362+
nextatom = lambda a: (a if id(a) not in memo
363+
else copymod.copy(a))
365364
mark = lambda a: (memo.add(id(a)), a)[-1]
366-
extatoms = (mark(newatom(a)) for a in atoms)
365+
newatoms = (mark(nextatom(a)) for a in atoms)
367366
elif copy:
368-
extatoms = adups
367+
newatoms = adups
369368
else:
370-
extatoms = atoms
369+
newatoms = atoms
371370
setlat = lambda a: (setattr(a, 'lattice', self.lattice), a)[-1]
372-
super(Structure, self).extend(setlat(a) for a in extatoms)
371+
super(Structure, self).extend(setlat(a) for a in newatoms)
373372
return
374373

375374

0 commit comments

Comments
 (0)