[issue9873] Allow bytes in some APIs that use string literals internally

Nick Coghlan report at bugs.python.org
Tue Sep 28 16:00:59 CEST 2010

Nick Coghlan <ncoghlan at gmail.com> added the comment:

Attached patch is a very rough first cut at this. I've gone with the basic approach of simply assigning the literals to local variables in each function that uses them. My rationale for that is:
1. Every function has to have some kind of boilerplate to switch based on the type of the argument
2. Some functions need to switch other values (such as the list of scheme_chars or the unparse function), so a separate object with literal attributes won't be enough
3. Given 1 and 2, the overhead of a separate namespace for the literal references isn't justified

I've also gone with a philosophy that only str objects are treated as strings and everything else is implicitly assumed to be bytes. This is in keeping with the general interpreter behaviour where we *really* don't support duck-typing when it comes to strings.

The test updates aren't comprehensive yet, but they were enough to uncover quite a few things I had missed.

quoting is still a bit ugly, so I may still add a byte->bytes/str->str variant of those APIs.

keywords: +patch
Added file: http://bugs.python.org/file19043/issue9873_initial_attempt.diff

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list