[Python-Dev] pprint(iterator) (original) (raw)
Paul Moore p.f.moore at gmail.com
Fri Jan 30 13:02:24 CET 2009
- Previous message: [Python-Dev] pprint(iterator)
- Next message: [Python-Dev] pprint(iterator)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
2009/1/30 Steven D'Aprano <steve at 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.
- Previous message: [Python-Dev] pprint(iterator)
- Next message: [Python-Dev] pprint(iterator)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]