File tree 1 file changed +16
-8
lines changed 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -2820,22 +2820,30 @@ are especially useful for annotating function and method arguments and are
2820
2820
decorated with :func: `@runtime_checkable <runtime_checkable> `.
2821
2821
2822
2822
.. class :: Reader[T]
2823
+
2824
+ Protocol for reading from a file or other I/O stream.
2825
+
2823
2826
.. method :: read(size=...)
2824
2827
.. method :: readline(size=...)
2825
2828
.. method :: __iter__()
2826
2829
2830
+ For example::
2831
+
2832
+ def read_it(reader: Reader[str]):
2833
+ assert reader.read(11) == "--marker--\n"
2834
+ for line in reader:
2835
+ print(line)
2836
+
2827
2837
.. class :: Writer[T]
2828
- .. method :: write(o)
2829
2838
2830
- For example::
2839
+ Protocol for writing to a file or other I/O stream.
2831
2840
2832
- def read_it(reader: Reader[str]):
2833
- assert reader.read(11) == "--marker--\n"
2834
- for line in reader:
2835
- print(line)
2841
+ .. method :: write(o)
2842
+
2843
+ For example::
2836
2844
2837
- def write_binary(writer: Writer[bytes]):
2838
- writer.write(b"Hello world!\n")
2845
+ def write_binary(writer: Writer[bytes]):
2846
+ writer.write(b"Hello world!\n")
2839
2847
2840
2848
Also consider using :class: `collections.abc.Iterable ` for iterating over
2841
2849
a stream::
You can’t perform that action at this time.
0 commit comments