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
62fe1bb9
Kaydet (Commit)
62fe1bb9
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 (add Coroutine, prohibit Generic[T]())
üst
b7dedc89
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
9 deletions
+45
-9
test_typing.py
Lib/test/test_typing.py
+22
-1
typing.py
Lib/typing.py
+23
-8
No files found.
Lib/test/test_typing.py
Dosyayı görüntüle @
62fe1bb9
...
...
@@ -517,6 +517,9 @@ class GenericTests(BaseTestCase):
Y
[
str
,
str
]
def
test_generic_errors
(
self
):
T
=
TypeVar
(
'T'
)
with
self
.
assertRaises
(
TypeError
):
Generic
[
T
]()
with
self
.
assertRaises
(
TypeError
):
isinstance
([],
List
[
int
])
with
self
.
assertRaises
(
TypeError
):
...
...
@@ -1255,7 +1258,7 @@ ASYNCIO = sys.version_info[:2] >= (3, 5)
ASYNCIO_TESTS
=
"""
import asyncio
T_a = TypeVar('T')
T_a = TypeVar('T
_a
')
class AwaitableWrapper(typing.Awaitable[T_a]):
...
...
@@ -1403,6 +1406,24 @@ class CollectionsAbcTests(BaseTestCase):
self
.
assertNotIsInstance
(
foo
,
typing
.
Awaitable
)
g
.
send
(
None
)
# Run foo() till completion, to avoid warning.
@skipUnless
(
ASYNCIO
,
'Python 3.5 and multithreading required'
)
def
test_coroutine
(
self
):
ns
=
{}
exec
(
"async def foo():
\n
"
" return
\n
"
,
globals
(),
ns
)
foo
=
ns
[
'foo'
]
g
=
foo
()
self
.
assertIsInstance
(
g
,
typing
.
Coroutine
)
with
self
.
assertRaises
(
TypeError
):
isinstance
(
g
,
typing
.
Coroutine
[
int
])
self
.
assertNotIsInstance
(
foo
,
typing
.
Coroutine
)
try
:
g
.
send
(
None
)
except
StopIteration
:
pass
@skipUnless
(
ASYNCIO
,
'Python 3.5 and multithreading required'
)
def
test_async_iterable
(
self
):
base_it
=
range
(
10
)
# type: Iterator[int]
...
...
Lib/typing.py
Dosyayı görüntüle @
62fe1bb9
...
...
@@ -29,9 +29,6 @@ __all__ = [
# ABCs (from collections.abc).
'AbstractSet'
,
# collections.abc.Set.
'Awaitable'
,
'AsyncIterator'
,
'AsyncIterable'
,
'ByteString'
,
'Container'
,
'Hashable'
,
...
...
@@ -47,6 +44,14 @@ __all__ = [
'Sequence'
,
'Sized'
,
'ValuesView'
,
# The following are added depending on presence
# of their non-generic counterparts in stdlib:
# Awaitable,
# AsyncIterator,
# AsyncIterable,
# Coroutine,
# Collection,
# ContextManager
# Structural checks, a.k.a. protocols.
'Reversible'
,
...
...
@@ -1104,6 +1109,9 @@ class Generic(metaclass=GenericMeta):
__slots__
=
()
def
__new__
(
cls
,
*
args
,
**
kwds
):
if
_geqv
(
cls
,
Generic
):
raise
TypeError
(
"Type Generic cannot be instantiated; "
"it can be used only as a base class"
)
return
_generic_new
(
cls
.
__next_in_mro__
,
cls
,
*
args
,
**
kwds
)
...
...
@@ -1639,8 +1647,16 @@ Hashable = collections_abc.Hashable # Not generic.
if
hasattr
(
collections_abc
,
'Awaitable'
):
class
Awaitable
(
Generic
[
T_co
],
extra
=
collections_abc
.
Awaitable
):
__slots__
=
()
else
:
Awaitable
=
None
__all__
.
append
(
'Awaitable'
)
if
hasattr
(
collections_abc
,
'Coroutine'
):
class
Coroutine
(
Awaitable
[
V_co
],
Generic
[
T_co
,
T_contra
,
V_co
],
extra
=
collections_abc
.
Coroutine
):
__slots__
=
()
__all__
.
append
(
'Coroutine'
)
if
hasattr
(
collections_abc
,
'AsyncIterable'
):
...
...
@@ -1652,9 +1668,8 @@ if hasattr(collections_abc, 'AsyncIterable'):
extra
=
collections_abc
.
AsyncIterator
):
__slots__
=
()
else
:
AsyncIterable
=
None
AsyncIterator
=
None
__all__
.
append
(
'AsyncIterable'
)
__all__
.
append
(
'AsyncIterator'
)
class
Iterable
(
Generic
[
T_co
],
extra
=
collections_abc
.
Iterable
):
...
...
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