New submission from Thomas Lee:

The main patch - while exactly what is needed to make str8/str equality
checks return False - breaks a bunch of tests due to PyString_* still
being used elsewhere when it should be using PyUnicode.

The second patch modifies structmember.c to use PyUnicode_* where it was
previously using PyString_*, which fixes the first problem I stumbled
across in trying to get test_unicode to run.

Unfortunately, similar errors are present in Python/codecs.c and other
places (maybe Python/modsupport.c too? not 100% sure yet) - these still
need to be fixed!

----------
components: Interpreter Core
files: unicode-string-eq-false-r2.patch
messages: 56343
nosy: thomas.lee
severity: normal
status: open
title: PEP 3137 patch - str8/str comparison should return false
type: rfe
versions: Python 3.0

__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1263>
__________________________________
Index: Objects/unicodeobject.c
===================================================================
--- Objects/unicodeobject.c	(revision 58389)
+++ Objects/unicodeobject.c	(working copy)
@@ -6191,16 +6191,6 @@
     if (PyUnicode_Check(left) && PyUnicode_Check(right))
         return unicode_compare((PyUnicodeObject *)left,
                                (PyUnicodeObject *)right);
-    if ((PyString_Check(left) && PyUnicode_Check(right)) ||
-        (PyUnicode_Check(left) && PyString_Check(right))) {
-        if (PyUnicode_Check(left))
-            left = _PyUnicode_AsDefaultEncodedString(left, NULL);
-        if (PyUnicode_Check(right))
-            right = _PyUnicode_AsDefaultEncodedString(right, NULL);
-        assert(PyString_Check(left));
-        assert(PyString_Check(right));
-        return PyObject_Compare(left, right);
-    }
     PyErr_Format(PyExc_TypeError,
                  "Can't compare %.100s and %.100s",
                  left->ob_type->tp_name,
Index: Lib/stringprep.py
===================================================================
--- Lib/stringprep.py	(revision 58389)
+++ Lib/stringprep.py	(working copy)
@@ -5,6 +5,8 @@
 and mappings, for which a mapping function is provided.
 """
 
+import sys
+
 from unicodedata import ucd_3_2_0 as unicodedata
 
 assert unicodedata.unidata_version == '3.2.0'
Index: Lib/test/test_unicode.py
===================================================================
--- Lib/test/test_unicode.py	(revision 58389)
+++ Lib/test/test_unicode.py	(working copy)
@@ -200,6 +200,10 @@
         self.checkequalnofix('[EMAIL PROTECTED]', 'one!two!three!', 'replace', '!', '@', 1)
         self.assertRaises(TypeError, 'replace'.replace, "r", 42)
 
+    def test_str8_comparison(self):
+        self.assertEqual('abc' == str8('abc'), False)
+        self.assertEqual('abc' != str8('abc'), True)
+
     def test_comparison(self):
         # Comparisons:
         self.assertEqual('abc', 'abc')
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to