File tree 5 files changed +85
-1
lines changed 5 files changed +85
-1
lines changed Original file line number Diff line number Diff line change 1
1
# Unreleased
2
2
3
3
- Drop support for Python 3.8 (including PyPy-3.8). Patch by [ Victorien Plot] ( https://github.com/Viicos ) .
4
+
5
+ New features:
6
+
4
7
- Add support for inline typed dictionaries ([ PEP 764] ( https://peps.python.org/pep-0764/ ) ).
5
8
Patch by [ Victorien Plot] ( https://github.com/Viicos ) .
9
+ - Add ` typing_extensions.Reader ` and ` typing_extensions.Writer ` . Patch by
10
+ Sebastian Rittau.
6
11
7
12
# Release 4.13.2 (April 10, 2025)
8
13
17
22
# Release 4.13.1 (April 3, 2025)
18
23
19
24
Bugfixes:
25
+
20
26
- Fix regression in 4.13.0 on Python 3.10.2 causing a ` TypeError ` when using ` Concatenate ` .
21
27
Patch by [ Daraan] ( https://github.com/Daraan ) .
22
28
- Fix ` TypeError ` when using ` evaluate_forward_ref ` on Python 3.10.1-2 and 3.9.8-10.
Original file line number Diff line number Diff line change 27
27
templates_path = ['_templates' ]
28
28
exclude_patterns = ['_build' , 'Thumbs.db' , '.DS_Store' ]
29
29
30
- intersphinx_mapping = {'py' : ('https://docs.python.org/3' , None )}
30
+ # This should usually point to /3, unless there is a necessity to link to
31
+ # features in future versions of Python.
32
+ intersphinx_mapping = {'py' : ('https://docs.python.org/3.14' , None )}
31
33
32
34
add_module_names = False
33
35
Original file line number Diff line number Diff line change @@ -659,6 +659,18 @@ Protocols
659
659
660
660
.. versionadded :: 4.6.0
661
661
662
+ .. class :: Reader
663
+
664
+ See :py:class: `io.Reader `. Added to the standard library in Python 3.14.
665
+
666
+ .. versionadded :: 4.14.0
667
+
668
+ .. class :: Writer
669
+
670
+ See :py:class: `io.Writer `. Added to the standard library in Python 3.14.
671
+
672
+ .. versionadded :: 4.14.0
673
+
662
674
Decorators
663
675
~~~~~~~~~~
664
676
Original file line number Diff line number Diff line change @@ -4103,6 +4103,32 @@ def foo(self): pass
4103
4103
self .assertIsSubclass (Bar , Functor )
4104
4104
4105
4105
4106
+ class SpecificProtocolTests (BaseTestCase ):
4107
+ def test_reader_runtime_checkable (self ):
4108
+ class MyReader :
4109
+ def read (self , n : int ) -> bytes :
4110
+ return b""
4111
+
4112
+ class WrongReader :
4113
+ def readx (self , n : int ) -> bytes :
4114
+ return b""
4115
+
4116
+ self .assertIsInstance (MyReader (), typing_extensions .Reader )
4117
+ self .assertNotIsInstance (WrongReader (), typing_extensions .Reader )
4118
+
4119
+ def test_writer_runtime_checkable (self ):
4120
+ class MyWriter :
4121
+ def write (self , b : bytes ) -> int :
4122
+ return 0
4123
+
4124
+ class WrongWriter :
4125
+ def writex (self , b : bytes ) -> int :
4126
+ return 0
4127
+
4128
+ self .assertIsInstance (MyWriter (), typing_extensions .Writer )
4129
+ self .assertNotIsInstance (WrongWriter (), typing_extensions .Writer )
4130
+
4131
+
4106
4132
class Point2DGeneric (Generic [T ], TypedDict ):
4107
4133
a : T
4108
4134
b : T
Original file line number Diff line number Diff line change 6
6
import enum
7
7
import functools
8
8
import inspect
9
+ import io
9
10
import keyword
10
11
import operator
11
12
import sys
56
57
'SupportsIndex' ,
57
58
'SupportsInt' ,
58
59
'SupportsRound' ,
60
+ 'Reader' ,
61
+ 'Writer' ,
59
62
60
63
# One-off things.
61
64
'Annotated' ,
@@ -846,6 +849,41 @@ def __round__(self, ndigits: int = 0) -> T_co:
846
849
pass
847
850
848
851
852
+ if hasattr (io , "Reader" ) and hasattr (io , "Writer" ):
853
+ Reader = io .Reader
854
+ Writer = io .Writer
855
+ else :
856
+ @runtime_checkable
857
+ class Reader (Protocol [T_co ]):
858
+ """Protocol for simple I/O reader instances.
859
+
860
+ This protocol only supports blocking I/O.
861
+ """
862
+
863
+ __slots__ = ()
864
+
865
+ @abc .abstractmethod
866
+ def read (self , size : int = ..., / ) -> T_co :
867
+ """Read data from the input stream and return it.
868
+
869
+ If *size* is specified, at most *size* items (bytes/characters) will be
870
+ read.
871
+ """
872
+
873
+ @runtime_checkable
874
+ class Writer (Protocol [T_contra ]):
875
+ """Protocol for simple I/O writer instances.
876
+
877
+ This protocol only supports blocking I/O.
878
+ """
879
+
880
+ __slots__ = ()
881
+
882
+ @abc .abstractmethod
883
+ def write (self , data : T_contra , / ) -> int :
884
+ """Write *data* to the output stream and return the number of items written.""" # noqa: E501
885
+
886
+
849
887
_NEEDS_SINGLETONMETA = (
850
888
not hasattr (typing , "NoDefault" ) or not hasattr (typing , "NoExtraItems" )
851
889
)
You can’t perform that action at this time.
0 commit comments