Re: Chanelling Guido - dict subclasses

2014-01-15 Thread Devin Jeanpierre
On Wed, Jan 15, 2014 at 8:51 AM, John Ladasky wrote: > On Wednesday, January 15, 2014 12:40:33 AM UTC-8, Peter Otten wrote: >> Personally I feel dirty whenever I write Python code that defeats duck- >> typing -- so I would not /recommend/ any isinstance() check. > > While I am inclined to agree, I

Re: Chanelling Guido - dict subclasses

2014-01-15 Thread Gregory Ewing
Daniel da Silva wrote: Just to be pedantic, this /is/ a violation of the Liskov Substution Principle. According to Wikipedia, the principle states: if S is a subtype of T, then objects of type T may be

Re: Chanelling Guido - dict subclasses

2014-01-15 Thread Daniel da Silva
On Tue, Jan 14, 2014 at 8:27 PM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > > But reading Guido, I think he's saying that wouldn't be a good idea. I > don't get it -- it's not a violation of the Liskov Substitution > Principle, because it's more restrictive, not less. What am

Re: Chanelling Guido - dict subclasses

2014-01-15 Thread Cameron Simpson
On 15Jan2014 05:03, Tim Chase wrote: > On 2014-01-15 01:27, Steven D'Aprano wrote: > > class TextOnlyDict(dict): > > def __setitem__(self, key, value): > > if not isinstance(key, str): > > raise TypeError > > super().__setitem__(key, value) > > # need to overrid

Re: Chanelling Guido - dict subclasses

2014-01-15 Thread Peter Otten
John Ladasky wrote: > On Wednesday, January 15, 2014 12:40:33 AM UTC-8, Peter Otten wrote: >> Personally I feel dirty whenever I write Python code that defeats duck- >> typing -- so I would not /recommend/ any isinstance() check. > > While I am inclined to agree, I have yet to see a solution to t

Re: Chanelling Guido - dict subclasses

2014-01-15 Thread John Ladasky
On Wednesday, January 15, 2014 12:40:33 AM UTC-8, Peter Otten wrote: > Personally I feel dirty whenever I write Python code that defeats duck- > typing -- so I would not /recommend/ any isinstance() check. While I am inclined to agree, I have yet to see a solution to the problem of flattening nes

Re: Chanelling Guido - dict subclasses

2014-01-15 Thread Tim Chase
On 2014-01-15 01:27, Steven D'Aprano wrote: > class TextOnlyDict(dict): > def __setitem__(self, key, value): > if not isinstance(key, str): > raise TypeError > super().__setitem__(key, value) > # need to override more methods too > > > But reading Guido, I thin

Re: Chanelling Guido - dict subclasses

2014-01-15 Thread Mark Lawrence
On 15/01/2014 01:27, Steven D'Aprano wrote: Over on the Python-Dev mailing list, there is an ENORMOUS multi-thread discussion involving at least two PEPs, about bytes/str compatibility. But I don't want to talk about that. (Oh gods, I *really* don't want to talk about that...) + trillions In

Re: Chanelling Guido - dict subclasses

2014-01-15 Thread Peter Otten
Steven D'Aprano wrote: > In the midst of that discussion, Guido van Rossum made a comment about > subclassing dicts: > > [quote] > Personally I wouldn't add any words suggesting or referring > to the option of creation another class for this purpose. You > wouldn't recommend subc

Re: Chanelling Guido - dict subclasses

2014-01-14 Thread F
I can't speak for Guido but I think it is messy and unnatural and will lead to user frustration. As a user, I would expect a dict to take any hashable as key and any object as value when using one. I would probably just provide a __getitem__ method in a normal class in your case. This said I

Re: Chanelling Guido - dict subclasses

2014-01-14 Thread Terry Reedy
On 1/14/2014 8:27 PM, Steven D'Aprano wrote: In the midst of that discussion, Guido van Rossum made a comment about subclassing dicts: [quote] From: Guido van Rossum Date: Tue, 14 Jan 2014 12:06:32 -0800 Subject: Re: [Python-Dev] PEP 460 reboot Personally I wouldn't a

Re: Chanelling Guido - dict subclasses

2014-01-14 Thread Ned Batchelder
On 1/14/14 8:27 PM, Steven D'Aprano wrote: Over on the Python-Dev mailing list, there is an ENORMOUS multi-thread discussion involving at least two PEPs, about bytes/str compatibility. But I don't want to talk about that. (Oh gods, I *really* don't want to talk about that...) In the midst of tha

Chanelling Guido - dict subclasses

2014-01-14 Thread Steven D'Aprano
Over on the Python-Dev mailing list, there is an ENORMOUS multi-thread discussion involving at least two PEPs, about bytes/str compatibility. But I don't want to talk about that. (Oh gods, I *really* don't want to talk about that...) In the midst of that discussion, Guido van Rossum made a comm