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
41f58a70
Kaydet (Commit)
41f58a70
authored
Ock 12, 2010
tarafından
Alexandre Vassalotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #7382: Fix bytes.__getnewargs__.
üst
a278be3c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
20 deletions
+45
-20
test_bytes.py
Lib/test/test_bytes.py
+40
-19
NEWS
Misc/NEWS
+4
-0
bytesobject.c
Objects/bytesobject.c
+1
-1
No files found.
Lib/test/test_bytes.py
Dosyayı görüntüle @
41f58a70
...
...
@@ -38,6 +38,13 @@ class BaseBytesTest(unittest.TestCase):
self
.
assertEqual
(
type
(
b
),
self
.
type2test
)
self
.
assertEqual
(
b
.
__class__
,
self
.
type2test
)
def
test_copy
(
self
):
a
=
self
.
type2test
(
b
"abcd"
)
for
copy_method
in
(
copy
.
copy
,
copy
.
deepcopy
):
b
=
copy_method
(
a
)
self
.
assertEqual
(
a
,
b
)
self
.
assertEqual
(
type
(
a
),
type
(
b
))
def
test_empty_sequence
(
self
):
b
=
self
.
type2test
()
self
.
assertEqual
(
len
(
b
),
0
)
...
...
@@ -996,17 +1003,14 @@ class BytesAsStringTest(FixedStringTest):
type2test
=
bytes
class
ByteArraySubclass
(
bytearray
):
pass
class
ByteArraySubclassTest
(
unittest
.
TestCase
):
class
SubclassTest
(
unittest
.
TestCase
):
def
test_basic
(
self
):
self
.
assertTrue
(
issubclass
(
ByteArraySubclass
,
bytearray
))
self
.
assertTrue
(
isinstance
(
ByteArraySubclass
(),
bytearray
))
self
.
assertTrue
(
issubclass
(
self
.
subclass2test
,
self
.
type2test
))
self
.
assertTrue
(
isinstance
(
self
.
subclass2test
(),
self
.
type2test
))
a
,
b
=
b
"abcd"
,
b
"efgh"
_a
,
_b
=
ByteArraySubclass
(
a
),
ByteArraySubclass
(
b
)
_a
,
_b
=
self
.
subclass2test
(
a
),
self
.
subclass2test
(
b
)
# test comparison operators with subclass instances
self
.
assertTrue
(
_a
==
_a
)
...
...
@@ -1029,19 +1033,19 @@ class ByteArraySubclassTest(unittest.TestCase):
# Make sure join returns a NEW object for single item sequences
# involving a subclass.
# Make sure that it is of the appropriate type.
s1
=
ByteArraySubclass
(
b
"abcd"
)
s2
=
bytearray
()
.
join
([
s1
])
s1
=
self
.
subclass2test
(
b
"abcd"
)
s2
=
self
.
type2test
()
.
join
([
s1
])
self
.
assertTrue
(
s1
is
not
s2
)
self
.
assertTrue
(
type
(
s2
)
is
bytearray
,
type
(
s2
))
self
.
assertTrue
(
type
(
s2
)
is
self
.
type2test
,
type
(
s2
))
# Test reverse, calling join on subclass
s3
=
s1
.
join
([
b
"abcd"
])
self
.
assertTrue
(
type
(
s3
)
is
bytearray
)
self
.
assertTrue
(
type
(
s3
)
is
self
.
type2test
)
def
test_pickle
(
self
):
a
=
ByteArraySubclass
(
b
"abcd"
)
a
=
self
.
subclass2test
(
b
"abcd"
)
a
.
x
=
10
a
.
y
=
ByteArraySubclass
(
b
"efgh"
)
a
.
y
=
self
.
subclass2test
(
b
"efgh"
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
b
=
pickle
.
loads
(
pickle
.
dumps
(
a
,
proto
))
self
.
assertNotEqual
(
id
(
a
),
id
(
b
))
...
...
@@ -1052,9 +1056,9 @@ class ByteArraySubclassTest(unittest.TestCase):
self
.
assertEqual
(
type
(
a
.
y
),
type
(
b
.
y
))
def
test_copy
(
self
):
a
=
ByteArraySubclass
(
b
"abcd"
)
a
=
self
.
subclass2test
(
b
"abcd"
)
a
.
x
=
10
a
.
y
=
ByteArraySubclass
(
b
"efgh"
)
a
.
y
=
self
.
subclass2test
(
b
"efgh"
)
for
copy_method
in
(
copy
.
copy
,
copy
.
deepcopy
):
b
=
copy_method
(
a
)
self
.
assertNotEqual
(
id
(
a
),
id
(
b
))
...
...
@@ -1064,21 +1068,38 @@ class ByteArraySubclassTest(unittest.TestCase):
self
.
assertEqual
(
type
(
a
),
type
(
b
))
self
.
assertEqual
(
type
(
a
.
y
),
type
(
b
.
y
))
class
ByteArraySubclass
(
bytearray
):
pass
class
BytesSubclass
(
bytes
):
pass
class
ByteArraySubclassTest
(
SubclassTest
):
type2test
=
bytearray
subclass2test
=
ByteArraySubclass
def
test_init_override
(
self
):
class
subclass
(
bytearray
):
def
__init__
(
self
,
newarg
=
1
,
*
args
,
**
kwargs
):
bytearray
.
__init__
(
self
,
*
args
,
**
kwargs
)
def
__init__
(
me
,
newarg
=
1
,
*
args
,
**
kwargs
):
bytearray
.
__init__
(
me
,
*
args
,
**
kwargs
)
x
=
subclass
(
4
,
b
"abcd"
)
x
=
subclass
(
4
,
source
=
b
"abcd"
)
self
.
assertEqual
(
x
,
b
"abcd"
)
x
=
subclass
(
newarg
=
4
,
source
=
b
"abcd"
)
self
.
assertEqual
(
x
,
b
"abcd"
)
class
BytesSubclassTest
(
SubclassTest
):
type2test
=
bytes
subclass2test
=
BytesSubclass
def
test_main
():
test
.
support
.
run_unittest
(
BytesTest
,
AssortedBytesTest
,
BytesAsStringTest
,
ByteArrayTest
,
ByteArrayAsStringTest
,
Byte
Array
SubclassTest
,
BytearrayPEP3137Test
)
ByteArrayTest
,
ByteArrayAsStringTest
,
Byte
s
SubclassTest
,
Byte
ArraySubclassTest
,
Byte
arrayPEP3137Test
)
if
__name__
==
"__main__"
:
test_main
()
Misc/NEWS
Dosyayı görüntüle @
41f58a70
...
...
@@ -152,6 +152,10 @@ Core and Builtins
- Issue #1023290: Add from_bytes() and to_bytes() methods to integers.
These methods allow the conversion of integers to bytes, and vice-versa.
- Issue #7382: Fix bug in bytes.__getnewargs__ that prevented bytes
instances from being copied with copy.copy(), and bytes subclasses
from being pickled properly.
C-API
-----
...
...
Objects/bytesobject.c
Dosyayı görüntüle @
41f58a70
...
...
@@ -2807,7 +2807,7 @@ bytes_sizeof(PyBytesObject *v)
static
PyObject
*
bytes_getnewargs
(
PyBytesObject
*
v
)
{
return
Py_BuildValue
(
"(
s
#)"
,
v
->
ob_sval
,
Py_SIZE
(
v
));
return
Py_BuildValue
(
"(
y
#)"
,
v
->
ob_sval
,
Py_SIZE
(
v
));
}
...
...
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