Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
18c3ff88
Kaydet (Commit)
18c3ff88
authored
Agu 29, 2007
tarafından
Jeremy Hylton
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make it an error to compare a bytes object and a Unicode object.
üst
991bf5d8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
7 deletions
+13
-7
test_bytes.py
Lib/test/test_bytes.py
+5
-5
bytesobject.c
Objects/bytesobject.c
+8
-2
No files found.
Lib/test/test_bytes.py
Dosyayı görüntüle @
18c3ff88
...
@@ -130,12 +130,12 @@ class BytesTest(unittest.TestCase):
...
@@ -130,12 +130,12 @@ class BytesTest(unittest.TestCase):
self
.
assertEqual
(
str8
(
"abc"
)
<
b
"ab"
,
False
)
self
.
assertEqual
(
str8
(
"abc"
)
<
b
"ab"
,
False
)
self
.
assertEqual
(
str8
(
"abc"
)
<=
b
"ab"
,
False
)
self
.
assertEqual
(
str8
(
"abc"
)
<=
b
"ab"
,
False
)
# Bytes
should never compare equal
to Unicode!
# Bytes
can't be compared
to Unicode!
# Test this for all expected byte orders and Unicode character sizes
# Test this for all expected byte orders and Unicode character sizes
self
.
assert
Equal
(
b
"
\0
a
\0
b
\0
c"
==
"abc"
,
False
)
self
.
assert
Raises
(
TypeError
,
lambda
:
b
"
\0
a
\0
b
\0
c"
==
"abc"
)
self
.
assert
Equal
(
b
"
\0\0\0
a
\0\0\0
b
\0\0\0
c"
==
"abc"
,
False
)
self
.
assert
Raises
(
TypeError
,
lambda
:
b
"
\0\0\0
a
\0\0\0
b
\0\0\0
c"
==
"abc"
)
self
.
assert
Equal
(
b
"a
\0
b
\0
c
\0
"
==
"abc"
,
False
)
self
.
assert
Raises
(
TypeError
,
lambda
:
b
"a
\0
b
\0
c
\0
"
==
"abc"
)
self
.
assert
Equal
(
b
"a
\0\0\0
b
\0\0\0
c
\0\0\0
"
==
"abc"
,
False
)
self
.
assert
Raises
(
TypeError
,
lambda
:
b
"a
\0\0\0
b
\0\0\0
c
\0\0\0
"
==
"abc"
)
def
test_nohash
(
self
):
def
test_nohash
(
self
):
self
.
assertRaises
(
TypeError
,
hash
,
bytes
())
self
.
assertRaises
(
TypeError
,
hash
,
bytes
())
...
...
Objects/bytesobject.c
Dosyayı görüntüle @
18c3ff88
...
@@ -959,8 +959,14 @@ bytes_richcompare(PyObject *self, PyObject *other, int op)
...
@@ -959,8 +959,14 @@ bytes_richcompare(PyObject *self, PyObject *other, int op)
Py_ssize_t
minsize
;
Py_ssize_t
minsize
;
int
cmp
;
int
cmp
;
/* Bytes can be compared to anything that supports the (binary) buffer
/* Bytes can be compared to anything that supports the (binary)
API. Except Unicode. */
buffer API. Except that a comparison with Unicode is always an
error, even if the comparison is for equality. */
if
(
PyObject_IsInstance
(
self
,
(
PyObject
*
)
&
PyUnicode_Type
)
||
PyObject_IsInstance
(
other
,
(
PyObject
*
)
&
PyUnicode_Type
))
{
PyErr_SetString
(
PyExc_TypeError
,
"can't compare bytes and str"
);
return
NULL
;
}
self_size
=
_getbuffer
(
self
,
&
self_bytes
);
self_size
=
_getbuffer
(
self
,
&
self_bytes
);
if
(
self_size
<
0
)
{
if
(
self_size
<
0
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment