On 2008-05-15 15:42, Nick Coghlan wrote:
M.-A. Lemburg wrote:
The .transform() methods would simply check for the corresponding
type combination, ie. str.transform() would check for (str, str).
str.encode() would check for (str, bytes), bytes.decode() for
(bytes, str).

Alternatively, we could just not check the type combinations
at all and only apply the result type check.

Note also that both bytearray and bytes provide decode() methods, and will presumably provide transform() methods, so actual type annotations may not be the best way to go about this.

I'm not sure I understand.

If we went with the approach of checking type annotations on the codec, then would a codec which was only annotated with (bytes, str) on the decode method be usable by bytearray.decode()?

Probably not, but the suggested form allows adding (bytearray, str)
if the codec support this as well and bytearray.decode() could check
for that combination.

And if we aren't going to check the type annotations before invoking the codec, what's the point in having them at all?

They provide meta-information about the codec capabilities and
may be useful in other contexts as well, e.g. if you want to
add an .encode() method to some other object.

 Better to leave them out
entirely, invoke the relevant method of the named codec and see if we get the right type back.

That's an option, yes.

OTOH, if you first decode a 100MB data string
using e.g. gzip and then find that the return type doesn't match
what you had expected, the added global warming due to wasted
CPU heat is going to make you feel rather uncomfortable :-)

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, May 15 2008)
>>> 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,MacOSX for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to