Issues with `codecs.register` and `codecs.CodecInfo` objects

Walter Dörwald walter at livinglogic.de
Tue Jul 10 16:49:05 CEST 2012


On 07.07.12 04:56, Steven D'Aprano wrote:

> On Fri, 06 Jul 2012 12:55:31 -0400, Karl Knechtel wrote:
>
>> Hello all,
>>
>> While attempting to make a wrapper for opening multiple types of
>> UTF-encoded files (more on that later, in a separate post, I guess), I
>> ran into some oddities with the `codecs` module, specifically to do with
>> `.register` ing `CodecInfo` objects. I'd like to report a bug or
>> something, but there are several intertangled issues here and I'm not
>> really sure how to report it so I thought I'd open the discussion.
>> Apologies in advance if I get a bit rant-y, and a warning that this is
>> fairly long.
> [...]
>
> Yes, it's a strangely indirect API, and yes it looks like you have
> identified a whole bucket full of problems with it. And no, I don't know
> why that API was chosen.

This API was chosen for backwards compatibility reasons when incremental 
encoders/decoders were introduced (in 2006).

And yes: We missed the opportunity to clean that up to always use CodecInfo.

> Changing to a cleaner, more direct (sensible?) API would be a fairly big
> step. If you want to pursue this, the steps I recommend you take are:
>
> 1) understanding the reason for the old API (search the Internet
>     and particularly the python-dev at python.org archives);

See e.g. http://mail.python.org/pipermail/patches/2006-March/019122.html

> 2) have a plan for how to avoid breaking code that relies on the
>     existing API;
>
> 3) raise the issue on python-ideas at python.org to gather feedback
>     and see how much opposition or support it is likely to get;
>     they'll suggest whether a bug report is sufficient or if you'll
>     need a PEP;
>
>     http://www.python.org/dev/peps/
>
>
> If you can provide a patch and a test suite, you will have a much better
> chance of pushing it through. If not, you are reliant on somebody else
> who can being interested enough to do the work.
>
> And one last thing: any new functionality will simply *not* be considered
> for Python 2.x. Aim for Python 3.4, since the 2.x series is now in bug-
> fix only maintenance mode and the 3.3 beta is no longer accepting new
> functionality, only bug fixes.

Servus,
    Walter



More information about the Python-list mailing list