Skip to content

Commit

Permalink
Give a more helpful error message if trying to use "set" on an ID obj…
Browse files Browse the repository at this point in the history
…ect (cf #380 and #381)
  • Loading branch information
apdavison committed May 25, 2016
1 parent 67605f8 commit f673f7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pyNN/common/populations.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class IDMixin(object):
def __getattr__(self, name):
if name == "parent":
raise Exception("parent is not set")
elif name == "set":
errmsg = "For individual cells, set values using the parameter name directly, " \
"e.g. population[0].tau_m = 20.0, or use 'set' on a population view, " \
"e.g. population[0:1].set(tau_m=20.0)"
raise AttributeError(errmsg)
try:
val = self.get_parameters()[name]
except KeyError:
Expand Down
6 changes: 5 additions & 1 deletion pyNN/common/procedural_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ def set(cells, **parameters):
PyNN units (i.e. millivolts, nanoamps, milliseconds, microsiemens,
nanofarads, event per second).
"""
assert isinstance(cells, (BasePopulation, Assembly))
if not isinstance(cells, (BasePopulation, Assembly)):
errmsg = "For individual cells, set values using the parameter name directly, " \
"e.g. population[0].tau_m = 20.0, or use 'set' on a population view, " \
"e.g. set(population[0:1], tau_m=20.0)"
raise AttributeError(errmsg)
cells.set(**parameters)


Expand Down

0 comments on commit f673f7e

Please sign in to comment.