[Patches] [ python-Patches-643443 ] dict.fromseq()

noreply@sourceforge.net noreply@sourceforge.net
Tue, 26 Nov 2002 00:53:36 -0800


Patches item #643443, was opened at 2002-11-25 05:29
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=643443&group_id=5470

Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
>Assigned to: Guido van Rossum (gvanrossum)
>Summary: dict.fromseq()

Initial Comment:
Implements dict.sequpdate() as discussed on python-
dev:

def sequpdate(self, iterable, value=True):
    for k in iterable:
        self[k] = value
    return self


----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-11-26 03:53

Message:
Logged In: YES 
user_id=80475

Done!  Revise patch attached.

It is now a class method and uses cls for the type of the 
new instance.  Added tests to demonstrate meaningful 
inheritance.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-11-25 20:15

Message:
Logged In: YES 
user_id=6380

Hm, but the convention for "alternate constructors" is that
the cls argument *is* used to determine the type of the new
instance. This way, the constructors are inherited in a
meaningful way by subclasses of dict.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2002-11-25 19:38

Message:
Logged In: YES 
user_id=80475

Attached revised patch incorporating all of the review 
comments.  Changed default to None.  Made a static 
method instead of a classmethod because cls was not 
used.  Doesn't return self.

Tests, docs, and news item revised accordingly.

Ready for BDFL pronouncement.

----------------------------------------------------------------------

Comment By: Just van Rossum (jvr)
Date: 2002-11-25 09:26

Message:
Logged In: YES 
user_id=92689

One more thing: I'd say the default value should be None.
This makes the idiom also useful to initialize dicts which
later get filled with proper values. This doesn't take
anything away from your original use case.

----------------------------------------------------------------------

Comment By: Just van Rossum (jvr)
Date: 2002-11-25 09:09

Message:
Logged In: YES 
user_id=92689

I see no reason why d.sequpdate() should return self.
d.update() doesn't either.

Also, as I suggested on python-dev, a fromseq() constructor
(as a class method) would be nice:

  >>> dict.fromseq('End Quit Stop Abort'.split())
  {'End': True, 'Quit': True, 'Stop': True, 'Abort': True}
  >>>

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=643443&group_id=5470