Skip to content

Instantly share code, notes, and snippets.

@Nurdok
Created January 12, 2013 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nurdok/4520107 to your computer and use it in GitHub Desktop.
Save Nurdok/4520107 to your computer and use it in GitHub Desktop.
"""TODO: A docstring"""
class Bean(type):
def __init__(cls, name, bases, dct):
def init(self, *args, **kwargs):
for attr, arg in zip(cls._attrs, args):
setattr(self, attr, arg)
for name, value in kwargs.iteritems():
setattr(self, name, value)
undefined = []
for attr in cls._attrs:
try:
getattr(self, attr)
except AttributeError:
undefined.append(attr)
if undefined:
print undefined
raise ValueError('The following arguments are missing: {0}'
.format(', '.join(undefined)))
setattr(cls, '__init__', init)
class Point(object):
__metaclass__ = Bean
_attrs = ('x', 'y')
p = Point(2, 5)
print p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment