Re: [Tutor] FrozenDict

2015-10-10 Thread Alexandre Chabot-Leclerc
> Aha, that's useful to know. So it's a no-no to subclass *any* builtin? I don't think it's a no-no, I just think it comes with a few problems that are solved if you subclass the classes that are *meant* to be subclassed, like UserDict, UserList, or UserString. > I checked collections.UserDict

Re: [Tutor] FrozenDict

2015-10-10 Thread Albert-Jan Roskam
> Date: Fri, 9 Oct 2015 01:14:05 -0500 > From: eryk...@gmail.com > To: tutor@python.org > Subject: Re: [Tutor] FrozenDict > > On 10/8/15, Steven D'Aprano wrote: >> >> That's one solution, but it is certainly

Re: [Tutor] FrozenDict

2015-10-10 Thread Albert-Jan Roskam
> Date: Thu, 8 Oct 2015 11:47:41 +1100 > From: st...@pearwood.info > To: tutor@python.org > Subject: Re: [Tutor] FrozenDict > > On Wed, Oct 07, 2015 at 04:10:20PM +, Albert-Jan Roskam wrote: >> Hi, >> I wanted to create

Re: [Tutor] FrozenDict

2015-10-10 Thread Albert-Jan Roskam
> From: a...@alexchabot.net > To: tutor@python.org > Date: Wed, 7 Oct 2015 18:54:42 +0200 > Subject: Re: [Tutor] FrozenDict > > Hi Albert-Jan, > As far as I know, the recommended object to subclass when subclassing a > `dict` is

Re: [Tutor] FrozenDict

2015-10-08 Thread eryksun
On 10/8/15, Steven D'Aprano wrote: > > That's one solution, but it is certainly possible for the class to be > its own iterator, in which case it needs to follow two rules: > > (1) self.__next__() needs to return the next value, or raise > StopIteration; > > (2) self.__iter__() needs to return sel

Re: [Tutor] FrozenDict

2015-10-08 Thread Steven D'Aprano
On Thu, Oct 08, 2015 at 12:03:28PM +0100, Oscar Benjamin wrote: > On 8 October 2015 at 01:47, Steven D'Aprano wrote: > > In 3.3, you will have a problem that FrozenDict is not a proper > > iterator. You can't set self.__next__ = self.next, that won't work. > > Dunder methods have to be on the clas

Re: [Tutor] FrozenDict

2015-10-08 Thread Oscar Benjamin
On 8 October 2015 at 01:47, Steven D'Aprano wrote: > In 3.3, you will have a problem that FrozenDict is not a proper > iterator. You can't set self.__next__ = self.next, that won't work. > Dunder methods have to be on the class, not on the instance, so instead > of making the assignment in the __i

Re: [Tutor] FrozenDict

2015-10-07 Thread Steven D'Aprano
On Wed, Oct 07, 2015 at 04:10:20PM +, Albert-Jan Roskam wrote: > Hi, > I wanted to create a read-only dict to hold some constants. I looked around > on the internet and created two implementations:-FrozenDict (derives from > collections.mapping)-ChillyDict (derives from dict, which seems more

Re: [Tutor] FrozenDict

2015-10-07 Thread Alexandre Chabot-Leclerc
Hi Albert-Jan, As far as I know, the recommended object to subclass when subclassing a `dict` is `UserDict`. In Python 3, it's in `collections.UserDict` and in Python 2 is in `UserDict.UserDict`. Here's an basic example of how it would work: try: from collections import UserDict except Impo

Re: [Tutor] FrozenDict

2015-10-07 Thread Albert-Jan Roskam
> From: sjeik_ap...@hotmail.com > To: tutor@python.org > Date: Wed, 7 Oct 2015 16:10:20 + > Subject: [Tutor] FrozenDict > > Hi, > I wanted to create a read-only dict to hold some constants. I looked around > on the internet and created two implementations:-

[Tutor] FrozenDict

2015-10-07 Thread Albert-Jan Roskam
Hi, I wanted to create a read-only dict to hold some constants. I looked around on the internet and created two implementations:-FrozenDict (derives from collections.mapping)-ChillyDict (derives from dict, which seems more obvious to me) The code can be found here: http://pastebin.com/QJ3V2mSK S