[Python-ideas] PEP-3151 pattern-matching
Nick Coghlan
ncoghlan at gmail.com
Thu Apr 7 13:48:01 CEST 2011
On Thu, Apr 7, 2011 at 7:17 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> Perhaps the IOError constructor could be made to switch
>> the class of the generated object based on the errno
>> attribute passed to the constructor.
>
> Nice suggestion. I'll try to see if that is possible.
It should be possible with appropriate fancy footwork in __new__. You
do need to be careful to avoid calling __init__ on the created object
twice.
I know I've read an example that demonstrates the principle, but I
unfortunately don't remember where (I initially thought it was in
Guido's new-style class essay, but I checked and that wasn't it)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list