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
f17c2007
Kaydet (Commit)
f17c2007
authored
Ara 04, 2015
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add Awaitable, AsyncIterable, AsyncIterator to typing.py.
üst
b1f64e7d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
0 deletions
+76
-0
test_typing.py
Lib/test/test_typing.py
+61
-0
typing.py
Lib/typing.py
+15
-0
No files found.
Lib/test/test_typing.py
Dosyayı görüntüle @
f17c2007
import
asyncio
import
pickle
import
re
import
sys
...
...
@@ -960,6 +961,36 @@ class OverloadTests(TestCase):
pass
T_a
=
TypeVar
(
'T'
)
class
AwaitableWrapper
(
typing
.
Awaitable
[
T_a
]):
def
__init__
(
self
,
value
):
self
.
value
=
value
def
__await__
(
self
)
->
typing
.
Iterator
[
T_a
]:
yield
return
self
.
value
class
AsyncIteratorWrapper
(
typing
.
AsyncIterator
[
T_a
]):
def
__init__
(
self
,
value
:
typing
.
Iterable
[
T_a
]):
self
.
value
=
value
def
__aiter__
(
self
)
->
typing
.
AsyncIterator
[
T_a
]:
return
self
@asyncio.coroutine
def
__anext__
(
self
)
->
T_a
:
data
=
yield
from
self
.
value
if
data
:
return
data
else
:
raise
StopAsyncIteration
class
CollectionsAbcTests
(
TestCase
):
def
test_hashable
(
self
):
...
...
@@ -984,6 +1015,36 @@ class CollectionsAbcTests(TestCase):
assert
isinstance
(
it
,
typing
.
Iterator
[
int
])
assert
not
isinstance
(
42
,
typing
.
Iterator
)
def
test_awaitable
(
self
):
async
def
foo
()
->
typing
.
Awaitable
[
int
]:
return
await
AwaitableWrapper
(
42
)
g
=
foo
()
assert
issubclass
(
type
(
g
),
typing
.
Awaitable
[
int
])
assert
isinstance
(
g
,
typing
.
Awaitable
)
assert
not
isinstance
(
foo
,
typing
.
Awaitable
)
assert
issubclass
(
typing
.
Awaitable
[
Manager
],
typing
.
Awaitable
[
Employee
])
assert
not
issubclass
(
typing
.
Awaitable
[
Employee
],
typing
.
Awaitable
[
Manager
])
g
.
send
(
None
)
# Run foo() till completion, to avoid warning.
def
test_async_iterable
(
self
):
base_it
=
range
(
10
)
# type: Iterator[int]
it
=
AsyncIteratorWrapper
(
base_it
)
assert
isinstance
(
it
,
typing
.
AsyncIterable
)
assert
isinstance
(
it
,
typing
.
AsyncIterable
)
assert
issubclass
(
typing
.
AsyncIterable
[
Manager
],
typing
.
AsyncIterable
[
Employee
])
assert
not
isinstance
(
42
,
typing
.
AsyncIterable
)
def
test_async_iterator
(
self
):
base_it
=
range
(
10
)
# type: Iterator[int]
it
=
AsyncIteratorWrapper
(
base_it
)
assert
isinstance
(
it
,
typing
.
AsyncIterator
)
assert
issubclass
(
typing
.
AsyncIterator
[
Manager
],
typing
.
AsyncIterator
[
Employee
])
assert
not
isinstance
(
42
,
typing
.
AsyncIterator
)
def
test_sized
(
self
):
assert
isinstance
([],
typing
.
Sized
)
assert
not
isinstance
(
42
,
typing
.
Sized
)
...
...
Lib/typing.py
Dosyayı görüntüle @
f17c2007
...
...
@@ -28,6 +28,9 @@ __all__ = [
# ABCs (from collections.abc).
'AbstractSet'
,
# collections.abc.Set.
'Awaitable'
,
'AsyncIterator'
,
'AsyncIterable'
,
'ByteString'
,
'Container'
,
'Hashable'
,
...
...
@@ -1261,6 +1264,18 @@ class _Protocol(metaclass=_ProtocolMeta):
Hashable
=
collections_abc
.
Hashable
# Not generic.
class
Awaitable
(
Generic
[
T_co
],
extra
=
collections_abc
.
Awaitable
):
__slots__
=
()
class
AsyncIterable
(
Generic
[
T_co
],
extra
=
collections_abc
.
AsyncIterable
):
__slots__
=
()
class
AsyncIterator
(
AsyncIterable
[
T_co
],
extra
=
collections_abc
.
AsyncIterator
):
__slots__
=
()
class
Iterable
(
Generic
[
T_co
],
extra
=
collections_abc
.
Iterable
):
__slots__
=
()
...
...
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