38
38
from typing_extensions import clear_overloads , get_overloads , overload
39
39
from typing_extensions import NamedTuple , TypeIs
40
40
from typing_extensions import override , deprecated , Buffer , TypeAliasType , TypeVar , get_protocol_members , is_protocol
41
- from typing_extensions import Doc
41
+ from typing_extensions import Doc , NoDefault
42
42
from _typed_dict_test_helper import Foo , FooGeneric , VeryAnnotated
43
43
44
44
# Flags used to mark tests that only apply after a specific
59
59
# versions, but not all
60
60
HAS_FORWARD_MODULE = "module" in inspect .signature (typing ._type_check ).parameters
61
61
62
- skip_if_early_py313_alpha = skipIf (
63
- sys .version_info [:4 ] == (3 , 13 , 0 , 'alpha' ) and sys . version_info . serial < 3 ,
64
- "Bugfixes will be released in 3.13.0a3 "
62
+ skip_if_py313_beta_1 = skipIf (
63
+ sys .version_info [:5 ] == (3 , 13 , 0 , 'beta' , 1 ) ,
64
+ "Bugfixes will be released in 3.13.0b2 "
65
65
)
66
66
67
67
ANN_MODULE_SOURCE = '''\
@@ -3485,7 +3485,6 @@ def method(self) -> None: ...
3485
3485
self .assertIsInstance (Foo (), ProtocolWithMixedMembers )
3486
3486
self .assertNotIsInstance (42 , ProtocolWithMixedMembers )
3487
3487
3488
- @skip_if_early_py313_alpha
3489
3488
def test_protocol_issubclass_error_message (self ):
3490
3489
@runtime_checkable
3491
3490
class Vec2D (Protocol ):
@@ -5917,7 +5916,6 @@ class GenericNamedTuple(NamedTuple, Generic[T]):
5917
5916
5918
5917
self .assertEqual (CallNamedTuple .__orig_bases__ , (NamedTuple ,))
5919
5918
5920
- @skip_if_early_py313_alpha
5921
5919
def test_setname_called_on_values_in_class_dictionary (self ):
5922
5920
class Vanilla :
5923
5921
def __set_name__ (self , owner , name ):
@@ -5989,7 +5987,6 @@ class NamedTupleClass(NamedTuple):
5989
5987
TYPING_3_12_0 ,
5990
5988
"__set_name__ behaviour changed on py312+ to use BaseException.add_note()"
5991
5989
)
5992
- @skip_if_early_py313_alpha
5993
5990
def test_setname_raises_the_same_as_on_other_classes_py312_plus (self ):
5994
5991
class CustomException (BaseException ): pass
5995
5992
@@ -6029,7 +6026,6 @@ class NamedTupleClass(NamedTuple):
6029
6026
normal_exception .__notes__ [0 ].replace ("NormalClass" , "NamedTupleClass" )
6030
6027
)
6031
6028
6032
- @skip_if_early_py313_alpha
6033
6029
def test_strange_errors_when_accessing_set_name_itself (self ):
6034
6030
class CustomException (Exception ): pass
6035
6031
@@ -6207,12 +6203,15 @@ class A(Generic[T]): ...
6207
6203
def test_typevar_none (self ):
6208
6204
U = typing_extensions .TypeVar ('U' )
6209
6205
U_None = typing_extensions .TypeVar ('U_None' , default = None )
6210
- self .assertEqual (U .__default__ , None )
6211
- self .assertEqual (U_None .__default__ , type (None ))
6206
+ self .assertIs (U .__default__ , NoDefault )
6207
+ self .assertFalse (U .has_default ())
6208
+ self .assertEqual (U_None .__default__ , None )
6209
+ self .assertTrue (U_None .has_default ())
6212
6210
6213
6211
def test_paramspec (self ):
6214
6212
P = ParamSpec ('P' , default = (str , int ))
6215
6213
self .assertEqual (P .__default__ , (str , int ))
6214
+ self .assertTrue (P .has_default ())
6216
6215
self .assertIsInstance (P , ParamSpec )
6217
6216
if hasattr (typing , "ParamSpec" ):
6218
6217
self .assertIsInstance (P , typing .ParamSpec )
@@ -6225,11 +6224,13 @@ class A(Generic[P]): ...
6225
6224
6226
6225
P_default = ParamSpec ('P_default' , default = ...)
6227
6226
self .assertIs (P_default .__default__ , ...)
6227
+ self .assertTrue (P_default .has_default ())
6228
6228
6229
6229
def test_typevartuple (self ):
6230
6230
Ts = TypeVarTuple ('Ts' , default = Unpack [Tuple [str , int ]])
6231
6231
self .assertEqual (Ts .__default__ , Unpack [Tuple [str , int ]])
6232
6232
self .assertIsInstance (Ts , TypeVarTuple )
6233
+ self .assertTrue (Ts .has_default ())
6233
6234
if hasattr (typing , "TypeVarTuple" ):
6234
6235
self .assertIsInstance (Ts , typing .TypeVarTuple )
6235
6236
typing_Ts = typing .TypeVarTuple ('Ts' )
@@ -6276,6 +6277,32 @@ def test_pickle(self):
6276
6277
self .assertEqual (z .__default__ , typevar .__default__ )
6277
6278
6278
6279
6280
+ class NoDefaultTests (BaseTestCase ):
6281
+ @skip_if_py313_beta_1
6282
+ def test_pickling (self ):
6283
+ for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
6284
+ s = pickle .dumps (NoDefault , proto )
6285
+ loaded = pickle .loads (s )
6286
+ self .assertIs (NoDefault , loaded )
6287
+
6288
+ def test_constructor (self ):
6289
+ self .assertIs (NoDefault , type (NoDefault )())
6290
+ with self .assertRaises (TypeError ):
6291
+ type (NoDefault )(1 )
6292
+
6293
+ def test_repr (self ):
6294
+ self .assertRegex (repr (NoDefault ), r'typing(_extensions)?\.NoDefault' )
6295
+
6296
+ def test_no_call (self ):
6297
+ with self .assertRaises (TypeError ):
6298
+ NoDefault ()
6299
+
6300
+ @skip_if_py313_beta_1
6301
+ def test_immutable (self ):
6302
+ with self .assertRaises (AttributeError ):
6303
+ NoDefault .foo = 'bar'
6304
+
6305
+
6279
6306
class TypeVarInferVarianceTests (BaseTestCase ):
6280
6307
def test_typevar (self ):
6281
6308
T = typing_extensions .TypeVar ('T' )
0 commit comments