Skip to content

Commit

Permalink
only issue _get_named_atom warning on successful call
Browse files Browse the repository at this point in the history
This allows code to use the `getattr` function and only throw
an error if the requested attribute is an atom name.
  • Loading branch information
kain88-de authored and richardjgowers committed Jun 21, 2017
1 parent 50f5d5a commit e24da32
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions package/MDAnalysis/core/topologyattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import itertools
import numbers
import numpy as np
import warnings

from numpy.lib.utils import deprecate

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

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

# AtomGroup already has a getattr
# transplants[AtomGroup].append(
Expand Down

0 comments on commit e24da32

Please sign in to comment.