Re: How to reduce the DRY violation in this code

2016-09-28 Thread Lorenzo Sutton
On 27/09/2016 17:49, Steve D'Aprano wrote: I have a class that takes a bunch of optional arguments. They're all optional, with default values of various types. For simplicity, let's say some are ints and some are floats: class Spam: def __init__(self, bashful=10.0, doc=20.0, dopey=30.0,

Re: How to reduce the DRY violation in this code

2016-09-28 Thread Yann Kaiser
You could use `attrs` for this along with the convert option, if you're open to receiving mixed arguments: >>> @attr.s ... class C(object): ... x = attr.ib(convert=int) >>> o = C("1") >>> o.x 1 https://attrs.readthedocs.io/en/stable/examples.html#conversion On Tue, Sep 27, 2016, 16:51 Steve D'Ap

Re: How to reduce the DRY violation in this code

2016-09-28 Thread alister
On Wed, 28 Sep 2016 01:49:56 +1000, Steve D'Aprano wrote: > I have a class that takes a bunch of optional arguments. They're all > optional, with default values of various types. For simplicity, let's > say some are ints and some are floats: > > > class Spam: > def __init__(self, bashful=10.

Re: How to reduce the DRY violation in this code

2016-09-27 Thread Wildman via Python-list
On Tue, 27 Sep 2016 10:30:05 -0700, Paul Rubin wrote: > Chris Angelico writes: >> Can you elaborate on what "GoF builder" means? Presumably it's a >> special case of the builder pattern, > > I think it just means the usual builder pattern, from the Design > Patterns book by the so-called Gang o

Re: How to reduce the DRY violation in this code

2016-09-27 Thread Paul Rubin
Chris Angelico writes: > Can you elaborate on what "GoF builder" means? Presumably it's a > special case of the builder pattern, I think it just means the usual builder pattern, from the Design Patterns book by the so-called Gang of Four (GoF). -- https://mail.python.org/mailman/listinfo/python

Re: How to reduce the DRY violation in this code

2016-09-27 Thread Chris Angelico
On Wed, Sep 28, 2016 at 3:08 AM, Gerald Britton wrote: >> >> I have a class that takes a bunch of optional arguments. They're all >> optional, with default values of various types. For simplicity, let's say >> some are ints and some are floats: class Spam: >> def __init__(self, bashful=10.0, doc=2

Re: How to reduce the DRY violation in this code

2016-09-27 Thread Paul Rubin
Steve D'Aprano writes: > class Spam: > def __init__(self, bashful=10.0, doc=20.0, dopey=30.0, > grumpy=40, happy=50, sleepy=60, sneezy=70): > # the usual assign arguments to attributes dance... > self.bashful = bashful > self.doc = doc > # etc.

RE: How to reduce the DRY violation in this code

2016-09-27 Thread Gerald Britton
> > I have a class that takes a bunch of optional arguments. They're all > optional, with default values of various types. For simplicity, let's say > some are ints and some are floats: class Spam: > def __init__(self, bashful=10.0, doc=20.0, dopey=30.0, > grumpy=40, happy=50, sleepy=60, sneezy=70)

Re: How to reduce the DRY violation in this code

2016-09-27 Thread Chris Angelico
On Wed, Sep 28, 2016 at 1:49 AM, Steve D'Aprano wrote: > @classmethod > def from_strings(cls, bashful='10.0', doc='20.0', dopey='30.0', > grumpy='40', happy='50', sleepy='60', sneezy='70'): > bashful = float(bashful) > doc = float(doc) > dopey =

Re: How to reduce the DRY violation in this code

2016-09-27 Thread Marko Rauhamaa
Steve D'Aprano : > def __init__(self, bashful=10.0, doc=20.0, dopey=30.0, > grumpy=40, happy=50, sleepy=60, sneezy=70): > [...] > > @classmethod > def from_strings(cls, bashful='10.0', doc='20.0', dopey='30.0', > grumpy='40', happy='50', sleepy='

How to reduce the DRY violation in this code

2016-09-27 Thread Steve D'Aprano
I have a class that takes a bunch of optional arguments. They're all optional, with default values of various types. For simplicity, let's say some are ints and some are floats: class Spam: def __init__(self, bashful=10.0, doc=20.0, dopey=30.0, grumpy=40, happy=50, sleepy=60