[Python-Dev] bytes.from_hex() [Was: PEP 332 revival in coordination with pep 349?] (original) (raw)

M.-A. Lemburg mal at egenix.com
Sat Feb 18 18:10:14 CET 2006


Martin v. Löwis wrote:

M.-A. Lemburg wrote:

I've already explained why we have .encode() and .decode() methods on strings and Unicode many times. I've also explained the misunderstanding that can codecs only do Unicode-string conversions. And I've explained that the .encode() and .decode() method do check the return types of the codecs and only allow strings or Unicode on return (no lists, instances, tuples or anything else).

You seem to ignore this fact. I'm not ignoring the fact that you have explained this many times. I just fail to understand your explanations.

Feel free to ask questions.

For example, you said at some point that codecs are not restricted to Unicode. However, I don't recall any explanation what the restriction is, if any restriction exists. No such restriction seems to be documented.

The codecs are not restricted w/r to the data types they work on. It's up to the codecs to define which data types are valid and which they take on input and return.

True. However, note that the .encode()/.decode() methods on strings and Unicode narrow down the possible return types. The corresponding .bytes methods should only allow bytes and Unicode. I forgot that: what is the rationale for that restriction?

To assure that only those types can be returned from those methods, ie. instances of basestring, which in return permits type inference for those methods.

The codecs functions encode() and decode() don't have these restrictions, and thus provide a generic interface to the codec's encode and decode functions. It's up to the caller to restrict the allowed encodings and as result the possible input/output types.

-- Marc-Andre Lemburg eGenix.com

Professional Python Services directly from the Source (#1, Feb 18 2006)

Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/


::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::



More information about the Python-Dev mailing list