2009/1/30 Steven D'Aprano <st...@pearwood.info>:
>> But that's beside the
>>
>> point, I don't like __pprint__ in any event. Too special.
>
> I'm not sure what you mean by "too special". It's no more special than any
> other special method. Do you mean the use-case is not common enough? I would
> find this useful. Whether enough people would find it useful enough to add
> yet another special method is an open question.

In my view, the issue is that as a special method, *either* it has to
be included on all core types (too intrusive for something as
non-critical as pprint) *or* pprint has to hard-code the behaviour for
core types and still fall back to the special method for non-core
types  (ugly and a maintenance problem keeping the type tests up to
date).

Some sort of registry of type-specific implementation functions
(whether you call it a generic function or just put together a custom
implementation for pprint alone) is more flexible, and less intrusive.
It also allows end users to customise the behaviour, even for core
types.

In all honesty, I think pkgutil.simplegeneric should be documented,
exposed, and moved to a library of its own[1]. It's precisely what is
needed for this type of situation, which does come up fairly often. I
don't think ABCs do what's needed here (although maybe I'm missing
something - if so, I'd be interested in knowing what).

I'd be willing to look at creating a patch, if the consensus was that
this was an appropriate approach and there was a reasonable chance of
it being accepted (assuming my code wasn't rubbish :-))

Paul.

[1] Note - I have no opinion on the quality of the code, I haven't
reviewed it, I am assuming it's OK on the basis that it has been
present and in use internally in the pkgutil module for some time now.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to