[Python-Dev] Allowing Unicode literals even without Unicode support?

Guido van Rossum guido@python.org
Fri, 24 May 2002 14:25:02 -0400


Many test modules fail because they use Unicode literals.  It's easy
enough to skip Unicode-related tests (just test for the existence of
'unicode'), but it's hard to avoid having Unicode literals in the text
at all.  Should we perhaps silently interpret Unicode literals as
regular string literals when compiling without Unicode support?

It's easy to do:

*** compile.c	26 Apr 2002 01:57:19 -0000	2.242
--- compile.c	24 May 2002 18:21:29 -0000
***************
*** 1135,1147 ****
  #endif
  	if (isalpha(quote) || quote == '_') {
  		if (quote == 'u' || quote == 'U') {
- #ifdef Py_USING_UNICODE
  			quote = *++s;
  			unicode = 1;
- #else
- 			com_error(com, PyExc_SyntaxError,
- 				  "Unicode literals not supported in this Python");
- 			return NULL;
  #endif
  		}
  		if (quote == 'r' || quote == 'R') {
--- 1135,1143 ----
  #endif
  	if (isalpha(quote) || quote == '_') {
  		if (quote == 'u' || quote == 'U') {
  			quote = *++s;
+ #ifdef Py_USING_UNICODE
  			unicode = 1;
  #endif
  		}
  		if (quote == 'r' || quote == 'R') {

--Guido van Rossum (home page: http://www.python.org/~guido/)