[Python-Dev] bytes / unicode

Michael Foord fuzzyman at voidspace.org.uk
Wed Jun 23 01:04:15 CEST 2010


On 22/06/2010 22:40, Robert Collins wrote:
> On Wed, Jun 23, 2010 at 6:09 AM, M.-A. Lemburg<mal at egenix.com>  wrote:
>
>    
>>>            return constant.encode('utf-8')
>>>
>>> So now you can write x.split(literal_as('&', x)).
>>>        
>> This polymorphism is what we used in Python2 a lot to write
>> code that works for both Unicode and 8-bit strings.
>>
>> Unfortunately, this no longer works as easily in Python3 due
>> to the literals sometimes having the wrong type and using
>> such a helper function slows things down a lot.
>>      
> I didn't work in 2 either - see for instance the traceback module with
> an Exception with unicode args and a non-ascii file path - the file
> path is in its bytes form, the string joining logic triggers an
> implicit upcast and *boom*.
>
>    
Yeah, there are still a few places in unittest where a unicode exception 
can cause the whole test run to bomb out. No-one has *yet* reported 
these as bugs and I try and ferret them out as I find them.

All the best,

Michael

>> Too bad we can't add such porting enhancements to Python2 anymore
>>      
> Perhaps a 'py3compat' module on pypi, with things like the py._builtin
> reraise helper and so forth ?
>
> -Rob
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk
>    


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.




More information about the Python-Dev mailing list