Skip to content

Commit e24da32

Browse files
kain88-derichardjgowers
authored andcommitted
only issue _get_named_atom warning on successful call
This allows code to use the `getattr` function and only throw an error if the requested attribute is an atom name.
1 parent 50f5d5a commit e24da32

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

package/MDAnalysis/core/topologyattrs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import itertools
4242
import numbers
4343
import numpy as np
44+
import warnings
4445

4546
from numpy.lib.utils import deprecate
4647

@@ -411,9 +412,6 @@ def getattr__(atomgroup, name):
411412
raise AttributeError("'{0}' object has no attribute '{1}'".format(
412413
atomgroup.__class__.__name__, name))
413414

414-
@deprecate(message="Instant selector AtomGroup['<name>'] or AtomGroup.<name> "
415-
"is deprecated and will be removed in 1.0. "
416-
"Use AtomGroup.select_atoms('name <name>') instead.")
417415
def _get_named_atom(group, name):
418416
"""Get all atoms with name *name* in the current AtomGroup.
419417
@@ -438,10 +436,12 @@ def _get_named_atom(group, name):
438436
"No atoms with name '{0}'".format(name))
439437
elif len(atomlist) == 1:
440438
# XXX: keep this, makes more sense for names
441-
return atomlist[0]
442-
else:
443-
# XXX: but inconsistent (see residues and Issue 47)
444-
return atomlist
439+
atomlist = atomlist[0]
440+
warnings.warn("Instant selector AtomGroup['<name>'] or AtomGroup.<name> "
441+
"is deprecated and will be removed in 1.0. "
442+
"Use AtomGroup.select_atoms('name <name>') instead.",
443+
DeprecationWarning)
444+
return atomlist
445445

446446
# AtomGroup already has a getattr
447447
# transplants[AtomGroup].append(

0 commit comments

Comments
 (0)