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
b7dedc89
Kaydet (Commit)
b7dedc89
authored
Eki 29, 2016
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #28556: updates to typing.py (fix copy, deepcopy, pickle)
üst
5fc25a87
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
+27
-0
test_typing.py
Lib/test/test_typing.py
+19
-0
typing.py
Lib/typing.py
+8
-0
No files found.
Lib/test/test_typing.py
Dosyayı görüntüle @
b7dedc89
...
...
@@ -4,6 +4,7 @@ import pickle
import
re
import
sys
from
unittest
import
TestCase
,
main
,
skipUnless
,
SkipTest
from
copy
import
copy
,
deepcopy
from
typing
import
Any
from
typing
import
TypeVar
,
AnyStr
...
...
@@ -845,6 +846,24 @@ class GenericTests(BaseTestCase):
self
.
assertEqual
(
x
.
foo
,
42
)
self
.
assertEqual
(
x
.
bar
,
'abc'
)
self
.
assertEqual
(
x
.
__dict__
,
{
'foo'
:
42
,
'bar'
:
'abc'
})
simples
=
[
Any
,
Union
,
Tuple
,
Callable
,
ClassVar
,
List
,
typing
.
Iterable
]
for
s
in
simples
:
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
z
=
pickle
.
dumps
(
s
,
proto
)
x
=
pickle
.
loads
(
z
)
self
.
assertEqual
(
s
,
x
)
def
test_copy_and_deepcopy
(
self
):
T
=
TypeVar
(
'T'
)
class
Node
(
Generic
[
T
]):
...
things
=
[
Union
[
T
,
int
],
Tuple
[
T
,
int
],
Callable
[
...
,
T
],
Callable
[[
int
],
int
],
Tuple
[
Any
,
Any
],
Node
[
T
],
Node
[
int
],
Node
[
Any
],
typing
.
Iterable
[
T
],
typing
.
Iterable
[
Any
],
typing
.
Iterable
[
int
],
typing
.
Dict
[
int
,
str
],
typing
.
Dict
[
T
,
Any
],
ClassVar
[
int
],
ClassVar
[
List
[
T
]],
Tuple
[
'T'
,
'T'
],
Union
[
'T'
,
int
],
List
[
'T'
],
typing
.
Mapping
[
'T'
,
int
]]
for
t
in
things
+
[
Any
]:
self
.
assertEqual
(
t
,
copy
(
t
))
self
.
assertEqual
(
t
,
deepcopy
(
t
))
def
test_errors
(
self
):
with
self
.
assertRaises
(
TypeError
):
...
...
Lib/typing.py
Dosyayı görüntüle @
b7dedc89
...
...
@@ -190,6 +190,9 @@ class _FinalTypingBase(_TypingBase, _root=True):
return
self
raise
TypeError
(
"Cannot instantiate
%
r"
%
cls
)
def
__reduce__
(
self
):
return
_trim_name
(
type
(
self
)
.
__name__
)
class
_ForwardRef
(
_TypingBase
,
_root
=
True
):
"""Wrapper to hold a forward reference."""
...
...
@@ -1051,6 +1054,11 @@ class GenericMeta(TypingMeta, abc.ABCMeta):
# classes are supposed to be rare anyways.
return
issubclass
(
instance
.
__class__
,
self
)
def
__copy__
(
self
):
return
self
.
__class__
(
self
.
__name__
,
self
.
__bases__
,
dict
(
self
.
__dict__
),
self
.
__parameters__
,
self
.
__args__
,
self
.
__origin__
,
self
.
__extra__
,
self
.
__orig_bases__
)
# Prevent checks for Generic to crash when defining Generic.
Generic
=
None
...
...
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