Skip to content
This repository has been archived by the owner on Jun 17, 2023. It is now read-only.

Commit

Permalink
Re-arrange loop
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Jun 28, 2014
1 parent ae914e4 commit 92902f8
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions characteristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,18 @@ def with_init(attrs, defaults=None):
defaults = {}

def init(self, *args, **kw):
for a in attrs:
try:
v = kw.pop(a)
except KeyError:
try:
v = defaults[a]
except KeyError:
raise ValueError(
"Missing keyword value for '{0}'.".format(a)
)
setattr(self, a, v)
try:
for a in attrs:
if a in defaults:
v = kw.pop(a, defaults[a])
else:
v = kw.pop(a)
setattr(self, a, v)
except KeyError as e:
raise ValueError(
"Missing keyword value for '{0}'.".format(e.args[0])
)

self.__original_init__(*args, **kw)

def wrap(cl):
Expand Down

0 comments on commit 92902f8

Please sign in to comment.