@@ -355,31 +355,84 @@ The module defines the following classes, functions and decorators:
355355
356356.. class :: MutableSequence(Sequence[T])
357357
358+ A generic version of :class: `collections.abc.MutableSequence `.
359+
358360.. class :: ByteString(Sequence[int])
359361
362+ A generic version of :class: `collections.abc.ByteString `.
363+
364+ This type represents the types :class: `bytes `, :class: `bytearray `,
365+ and :class: `memoryview `.
366+
367+ As a shorthand for this type, :class: `bytes ` can be used to
368+ annotate arguments of any of the types mentioned above.
369+
360370.. class :: List(list, MutableSequence[T])
361371
362- .. class :: Set(set, MutableSet[T])
372+ Generic version of :class: `list `.
373+ Useful for annotating return types. To annotate arguments it is preferred
374+ to use abstract collection types such as :class: `Mapping `, :class: `Sequence `,
375+ or :class: `AbstractSet `.
376+
377+ This type may be used as follows::
378+
379+ T = TypeVar('T', int, float)
380+
381+ def vec2(x: T, y: T) -> List[T]:
382+ return [x, y]
383+
384+ def slice__to_4(vector: Sequence[T]) -> List[T]:
385+ return vector[0:4]
386+
387+ .. class :: AbstractSet(set, MutableSet[T])
388+
389+ A generic version of :class: `collections.abc.Set `.
363390
364391.. class :: MappingView(Sized, Iterable[T_co])
365392
393+ A generic version of :class: `collections.abc.MappingView `.
394+
366395.. class :: KeysView(MappingView[KT_co], AbstractSet[KT_co])
367396
397+ A generic version of :class: `collections.abc.KeysView `.
398+
368399.. class :: ItemsView(MappingView, Generic[KT_co, VT_co])
369400
401+ A generic version of :class: `collections.abc.ItemsView `.
402+
370403.. class :: ValuesView(MappingView[VT_co])
371404
405+ A generic version of :class: `collections.abc.ValuesView `.
406+
372407.. class :: Dict(dict, MutableMapping[KT, VT])
373408
409+ A generic version of :class: `dict `.
410+ The usage of this type is as follows::
411+
412+ def get_position_in_index(word_list: Dict[str, int], word: str) -> int:
413+ return word_list[word]
414+
374415.. class :: Generator(Iterator[T_co], Generic[T_co, T_contra, V_co])
375416
376417.. class :: io
377418
378- Wrapper namespace for IO generic classes.
419+ Wrapper namespace for I/O stream types.
420+
421+ This defines the generic type ``IO[AnyStr] `` and aliases ``TextIO ``
422+ and ``BinaryIO `` for respectively ``IO[str] `` and ``IO[bytes] ``.
423+ These representing the types of I/O streams such as returned by
424+ :func: `open `.
379425
380426.. class :: re
381427
382- Wrapper namespace for re type classes.
428+ Wrapper namespace for regular expression matching types.
429+
430+ This defines the type aliases ``Pattern `` and ``Match `` which
431+ correspond to the return types from :func: `re.compile ` and
432+ :func: `re.match `. These types (and the corresponding functions)
433+ are generic in ``AnyStr `` and can be made specific by writing
434+ ``Pattern[str] ``, ``Pattern[bytes] ``, ``Match[str] ``, or
435+ ``Match[bytes] ``.
383436
384437.. function :: NamedTuple(typename, fields)
385438
0 commit comments