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
31ec52a9
Kaydet (Commit)
31ec52a9
authored
Ock 04, 2019
tarafından
Ville Skyttä
Kaydeden (comit)
Ivan Levkivskyi
Ock 04, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-35631: Improve typing docs wrt abstract/concrete collection types (GH-11396)
https://bugs.python.org/issue35631
üst
47a2fced
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
8 deletions
+17
-8
typing.rst
Doc/library/typing.rst
+17
-8
No files found.
Doc/library/typing.rst
Dosyayı görüntüle @
31ec52a9
...
@@ -50,20 +50,20 @@ A type alias is defined by assigning the type to the alias. In this example,
...
@@ -50,20 +50,20 @@ A type alias is defined by assigning the type to the alias. In this example,
Type aliases are useful for simplifying complex type signatures. For example::
Type aliases are useful for simplifying complex type signatures. For example::
from typing import Dict, Tuple,
List
from typing import Dict, Tuple,
Sequence
ConnectionOptions = Dict[str, str]
ConnectionOptions = Dict[str, str]
Address = Tuple[str, int]
Address = Tuple[str, int]
Server = Tuple[Address, ConnectionOptions]
Server = Tuple[Address, ConnectionOptions]
def broadcast_message(message: str, servers:
List
[Server]) -> None:
def broadcast_message(message: str, servers:
Sequence
[Server]) -> None:
...
...
# The static type checker will treat the previous type signature as
# The static type checker will treat the previous type signature as
# being exactly equivalent to this one.
# being exactly equivalent to this one.
def broadcast_message(
def broadcast_message(
message: str,
message: str,
servers:
List
[Tuple[Tuple[str, int], Dict[str, str]]]) -> None:
servers:
Sequence
[Tuple[Tuple[str, int], Dict[str, str]]]) -> None:
...
...
Note that ``None`` as a type hint is a special case and is replaced by
Note that ``None`` as a type hint is a special case and is replaced by
...
@@ -568,6 +568,10 @@ The module defines the following classes, functions and decorators:
...
@@ -568,6 +568,10 @@ The module defines the following classes, functions and decorators:
.. class:: Mapping(Sized, Collection[KT], Generic[VT_co])
.. class:: Mapping(Sized, Collection[KT], Generic[VT_co])
A generic version of :class:`collections.abc.Mapping`.
A generic version of :class:`collections.abc.Mapping`.
This type can be used as follows::
def get_position_in_index(word_list: Mapping[str, int], word: str) -> int:
return word_list[word]
.. class:: MutableMapping(Mapping[KT, VT])
.. class:: MutableMapping(Mapping[KT, VT])
...
@@ -601,8 +605,8 @@ The module defines the following classes, functions and decorators:
...
@@ -601,8 +605,8 @@ The module defines the following classes, functions and decorators:
Generic version of :class:`list`.
Generic version of :class:`list`.
Useful for annotating return types. To annotate arguments it is preferred
Useful for annotating return types. To annotate arguments it is preferred
to use a
bstract collection types such as :class:`Mapping`, :class:`Sequence`,
to use a
n abstract collection type such as :class:`Sequence` or
or :class:`AbstractSet
`.
:class:`Iterable
`.
This type may be used as follows::
This type may be used as follows::
...
@@ -617,6 +621,8 @@ The module defines the following classes, functions and decorators:
...
@@ -617,6 +621,8 @@ The module defines the following classes, functions and decorators:
.. class:: Set(set, MutableSet[T])
.. class:: Set(set, MutableSet[T])
A generic version of :class:`builtins.set <set>`.
A generic version of :class:`builtins.set <set>`.
Useful for annotating return types. To annotate arguments it is preferred
to use an abstract collection type such as :class:`AbstractSet`.
.. class:: FrozenSet(frozenset, AbstractSet[T_co])
.. class:: FrozenSet(frozenset, AbstractSet[T_co])
...
@@ -678,10 +684,13 @@ The module defines the following classes, functions and decorators:
...
@@ -678,10 +684,13 @@ The module defines the following classes, functions and decorators:
.. class:: Dict(dict, MutableMapping[KT, VT])
.. class:: Dict(dict, MutableMapping[KT, VT])
A generic version of :class:`dict`.
A generic version of :class:`dict`.
The usage of this type is as follows::
Useful for annotating return types. To annotate arguments it is preferred
to use an abstract collection type such as :class:`Mapping`.
def get_position_in_index(word_list: Dict[str, int], word: str) -> int:
This type can be used as follows::
return word_list[word]
def count_words(text: str) -> Dict[str, int]:
...
.. class:: DefaultDict(collections.defaultdict, MutableMapping[KT, VT])
.. class:: DefaultDict(collections.defaultdict, MutableMapping[KT, VT])
...
...
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