@@ -651,7 +651,7 @@ def h(x: int) -> int: ...
651
651
@overload
652
652
def h (x : str ) -> str : ...
653
653
def h (x ):
654
- return x
654
+ return x # pragma: no cover
655
655
656
656
overloads = get_overloads (h )
657
657
self .assertEqual (len (overloads ), 2 )
@@ -1516,15 +1516,15 @@ def __init__(self, value):
1516
1516
1517
1517
def __await__ (self ) -> typing .Iterator [T_a ]:
1518
1518
yield
1519
- return self .value
1519
+ return self .value # pragma: no cover
1520
1520
1521
1521
class AsyncIteratorWrapper (AsyncIterator [T_a ]):
1522
1522
1523
1523
def __init__ (self , value : Iterable [T_a ]):
1524
1524
self .value = value
1525
1525
1526
1526
def __aiter__ (self ) -> AsyncIterator [T_a ]:
1527
- return self
1527
+ return self # pragma: no cover
1528
1528
1529
1529
async def __anext__ (self ) -> T_a :
1530
1530
data = await self .value
@@ -2039,7 +2039,7 @@ class GeneratorTests(BaseTestCase):
2039
2039
2040
2040
def test_generator_basics (self ):
2041
2041
def foo ():
2042
- yield 42
2042
+ yield 42 # pragma: no cover
2043
2043
g = foo ()
2044
2044
2045
2045
self .assertIsInstance (g , typing_extensions .Generator )
@@ -2097,7 +2097,7 @@ def g(): yield 0
2097
2097
2098
2098
def test_async_generator_basics (self ):
2099
2099
async def f ():
2100
- yield 42
2100
+ yield 42 # pragma: no cover
2101
2101
g = f ()
2102
2102
2103
2103
self .assertIsInstance (g , typing_extensions .AsyncGenerator )
@@ -2216,7 +2216,7 @@ class OtherABCTests(BaseTestCase):
2216
2216
def test_contextmanager (self ):
2217
2217
@contextlib .contextmanager
2218
2218
def manager ():
2219
- yield 42
2219
+ yield 42 # pragma: no cover
2220
2220
2221
2221
cm = manager ()
2222
2222
self .assertIsInstance (cm , typing_extensions .ContextManager )
@@ -2235,7 +2235,7 @@ class NotACM:
2235
2235
self .assertNotIsInstance (NotACM (), typing_extensions .AsyncContextManager )
2236
2236
@contextlib .contextmanager
2237
2237
def manager ():
2238
- yield 42
2238
+ yield 42 # pragma: no cover
2239
2239
2240
2240
cm = manager ()
2241
2241
self .assertNotIsInstance (cm , typing_extensions .AsyncContextManager )
@@ -2614,7 +2614,7 @@ class B(P):
2614
2614
pass
2615
2615
class C (B ):
2616
2616
def ameth (self ) -> int :
2617
- return 26
2617
+ return 26 # pragma: no cover
2618
2618
with self .assertRaises (TypeError ):
2619
2619
B ()
2620
2620
self .assertIsInstance (C (), P )
@@ -3032,11 +3032,11 @@ def test_protocols_isinstance_properties_and_descriptors(self):
3032
3032
class C :
3033
3033
@property
3034
3034
def attr (self ):
3035
- return 42
3035
+ return 42 # pragma: no cover
3036
3036
3037
3037
class CustomDescriptor :
3038
3038
def __get__ (self , obj , objtype = None ):
3039
- return 42
3039
+ return 42 # pragma: no cover
3040
3040
3041
3041
class D :
3042
3042
attr = CustomDescriptor ()
@@ -3120,11 +3120,11 @@ class HasX(Protocol):
3120
3120
class CustomDirWithX :
3121
3121
x = 10
3122
3122
def __dir__ (self ):
3123
- return []
3123
+ return [] # pragma: no cover
3124
3124
3125
3125
class CustomDirWithoutX :
3126
3126
def __dir__ (self ):
3127
- return ["x" ]
3127
+ return ["x" ] # pragma: no cover
3128
3128
3129
3129
self .assertIsInstance (CustomDirWithX (), HasX )
3130
3130
self .assertNotIsInstance (CustomDirWithoutX (), HasX )
@@ -3133,11 +3133,11 @@ def test_protocols_isinstance_attribute_access_with_side_effects(self):
3133
3133
class C :
3134
3134
@property
3135
3135
def attr (self ):
3136
- raise AttributeError ('no' )
3136
+ raise AttributeError ('no' ) # pragma: no cover
3137
3137
3138
3138
class CustomDescriptor :
3139
3139
def __get__ (self , obj , objtype = None ):
3140
- raise RuntimeError ("NO" )
3140
+ raise RuntimeError ("NO" ) # pragma: no cover
3141
3141
3142
3142
class D :
3143
3143
attr = CustomDescriptor ()
@@ -3149,7 +3149,7 @@ class F(D): ...
3149
3149
3150
3150
class WhyWouldYouDoThis :
3151
3151
def __getattr__ (self , name ):
3152
- raise RuntimeError ("wut" )
3152
+ raise RuntimeError ("wut" ) # pragma: no cover
3153
3153
3154
3154
T = TypeVar ('T' )
3155
3155
@@ -3220,7 +3220,7 @@ class C:
3220
3220
def __init__ (self , attr ):
3221
3221
self .attr = attr
3222
3222
def meth (self , arg ):
3223
- return 0
3223
+ return 0 # pragma: no cover
3224
3224
class Bad : pass
3225
3225
self .assertIsInstance (APoint (1 , 2 , 'A' ), Point )
3226
3226
self .assertIsInstance (BPoint (1 , 2 ), Point )
@@ -3491,7 +3491,7 @@ class ImplementsHasX:
3491
3491
class NotRuntimeCheckable (Protocol ):
3492
3492
@classmethod
3493
3493
def __subclasshook__ (cls , other ):
3494
- return hasattr (other , 'x' )
3494
+ return hasattr (other , 'x' ) # pragma: no cover
3495
3495
3496
3496
must_be_runtime_checkable = (
3497
3497
"Instance and class checks can only be used "
@@ -3577,7 +3577,7 @@ class PSub(P1[str], Protocol):
3577
3577
class Test :
3578
3578
x = 1
3579
3579
def bar (self , x : str ) -> str :
3580
- return x
3580
+ return x # pragma: no cover
3581
3581
self .assertIsInstance (Test (), PSub )
3582
3582
if not TYPING_3_10_0 :
3583
3583
with self .assertRaises (TypeError ):
@@ -3765,9 +3765,9 @@ def close(self): pass
3765
3765
class A : ...
3766
3766
class B :
3767
3767
def __iter__ (self ):
3768
- return []
3768
+ return [] # pragma: no cover
3769
3769
def close (self ):
3770
- return 0
3770
+ return 0 # pragma: no cover
3771
3771
3772
3772
self .assertIsSubclass (B , Custom )
3773
3773
self .assertNotIsSubclass (A , Custom )
@@ -3785,7 +3785,7 @@ def __release_buffer__(self, mv: memoryview) -> None: ...
3785
3785
class C : pass
3786
3786
class D :
3787
3787
def __buffer__ (self , flags : int ) -> memoryview :
3788
- return memoryview (b'' )
3788
+ return memoryview (b'' ) # pragma: no cover
3789
3789
def __release_buffer__ (self , mv : memoryview ) -> None :
3790
3790
pass
3791
3791
@@ -3811,7 +3811,7 @@ def __release_buffer__(self, mv: memoryview) -> None: ...
3811
3811
class C : pass
3812
3812
class D :
3813
3813
def __buffer__ (self , flags : int ) -> memoryview :
3814
- return memoryview (b'' )
3814
+ return memoryview (b'' ) # pragma: no cover
3815
3815
def __release_buffer__ (self , mv : memoryview ) -> None :
3816
3816
pass
3817
3817
@@ -4095,7 +4095,7 @@ class Vec2D(Protocol):
4095
4095
y : float
4096
4096
4097
4097
def square_norm (self ) -> float :
4098
- return self .x ** 2 + self .y ** 2
4098
+ return self .x ** 2 + self .y ** 2 # pragma: no cover
4099
4099
4100
4100
self .assertEqual (Vec2D .__protocol_attrs__ , {'x' , 'y' , 'square_norm' })
4101
4101
expected_error_message = (
@@ -4108,7 +4108,7 @@ def square_norm(self) -> float:
4108
4108
def test_nonruntime_protocol_interaction_with_evil_classproperty (self ):
4109
4109
class classproperty :
4110
4110
def __get__ (self , instance , type ):
4111
- raise RuntimeError ("NO" )
4111
+ raise RuntimeError ("NO" ) # pragma: no cover
4112
4112
4113
4113
class Commentable (Protocol ):
4114
4114
evil = classproperty ()
@@ -4155,23 +4155,23 @@ class SpecificProtocolTests(BaseTestCase):
4155
4155
def test_reader_runtime_checkable (self ):
4156
4156
class MyReader :
4157
4157
def read (self , n : int ) -> bytes :
4158
- return b""
4158
+ return b"" # pragma: no cover
4159
4159
4160
4160
class WrongReader :
4161
4161
def readx (self , n : int ) -> bytes :
4162
- return b""
4162
+ return b"" # pragma: no cover
4163
4163
4164
4164
self .assertIsInstance (MyReader (), typing_extensions .Reader )
4165
4165
self .assertNotIsInstance (WrongReader (), typing_extensions .Reader )
4166
4166
4167
4167
def test_writer_runtime_checkable (self ):
4168
4168
class MyWriter :
4169
4169
def write (self , b : bytes ) -> int :
4170
- return 0
4170
+ return 0 # pragma: no cover
4171
4171
4172
4172
class WrongWriter :
4173
4173
def writex (self , b : bytes ) -> int :
4174
- return 0
4174
+ return 0 # pragma: no cover
4175
4175
4176
4176
self .assertIsInstance (MyWriter (), typing_extensions .Writer )
4177
4177
self .assertNotIsInstance (WrongWriter (), typing_extensions .Writer )
@@ -5959,7 +5959,7 @@ def run():
5959
5959
proc = subprocess .run (
5960
5960
[sys .executable , "-c" , code ], check = True , capture_output = True , text = True ,
5961
5961
)
5962
- except subprocess .CalledProcessError as exc :
5962
+ except subprocess .CalledProcessError as exc : # pragma: no cover
5963
5963
print ("stdout" , exc .stdout , sep = "\n " )
5964
5964
print ("stderr" , exc .stderr , sep = "\n " )
5965
5965
raise
@@ -6324,7 +6324,7 @@ def test_alias(self):
6324
6324
StringTuple = Tuple [LiteralString , LiteralString ]
6325
6325
class Alias :
6326
6326
def return_tuple (self ) -> StringTuple :
6327
- return ("foo" , "pep" + "675" )
6327
+ return ("foo" , "pep" + "675" ) # pragma: no cover
6328
6328
6329
6329
def test_typevar (self ):
6330
6330
StrT = TypeVar ("StrT" , bound = LiteralString )
@@ -6375,7 +6375,7 @@ def test_alias(self):
6375
6375
TupleSelf = Tuple [Self , Self ]
6376
6376
class Alias :
6377
6377
def return_tuple (self ) -> TupleSelf :
6378
- return (self , self )
6378
+ return (self , self ) # pragma: no cover
6379
6379
6380
6380
def test_pickle (self ):
6381
6381
for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
@@ -6615,7 +6615,7 @@ class Wrapper:
6615
6615
def __init__ (self , func ):
6616
6616
self .func = func
6617
6617
def __call__ (self , * args , ** kwargs ):
6618
- return self .func (* args , ** kwargs )
6618
+ return self .func (* args , ** kwargs ) # pragma: no cover
6619
6619
6620
6620
# Check that no error is thrown if the attribute
6621
6621
# is not writable.
@@ -6899,7 +6899,7 @@ def test_typing_extensions_compiles_with_opt(self):
6899
6899
subprocess .check_output (f'{ sys .executable } -OO { file_path } ' ,
6900
6900
stderr = subprocess .STDOUT ,
6901
6901
shell = True )
6902
- except subprocess .CalledProcessError :
6902
+ except subprocess .CalledProcessError : # pragma: no cover
6903
6903
self .fail ('Module does not compile with optimize=2 (-OO flag).' )
6904
6904
6905
6905
@@ -6989,13 +6989,13 @@ def test_annotation_usage_with_methods(self):
6989
6989
class XMethBad (NamedTuple ):
6990
6990
x : int
6991
6991
def _fields (self ):
6992
- return 'no chance for this'
6992
+ return 'no chance for this' # pragma: no cover
6993
6993
6994
6994
with self .assertRaisesRegex (AttributeError , bad_overwrite_error_message ):
6995
6995
class XMethBad2 (NamedTuple ):
6996
6996
x : int
6997
6997
def _source (self ):
6998
- return 'no chance for this as well'
6998
+ return 'no chance for this as well' # pragma: no cover
6999
6999
7000
7000
def test_multiple_inheritance (self ):
7001
7001
class A :
@@ -7660,7 +7660,7 @@ def test_generic_with_broken_eq(self):
7660
7660
class BrokenEq (type ):
7661
7661
def __eq__ (self , other ):
7662
7662
if other is typing_extensions .Protocol :
7663
- raise TypeError ("I'm broken" )
7663
+ raise TypeError ("I'm broken" ) # pragma: no cover
7664
7664
return False
7665
7665
7666
7666
class G (Generic [T ], metaclass = BrokenEq ):
@@ -7786,7 +7786,7 @@ def test(self):
7786
7786
7787
7787
class MyRegisteredBuffer :
7788
7788
def __buffer__ (self , flags : int ) -> memoryview :
7789
- return memoryview (b'' )
7789
+ return memoryview (b'' ) # pragma: no cover
7790
7790
7791
7791
# On 3.12, collections.abc.Buffer does a structural compatibility check
7792
7792
if TYPING_3_12_0 :
@@ -7801,7 +7801,7 @@ def __buffer__(self, flags: int) -> memoryview:
7801
7801
7802
7802
class MySubclassedBuffer (Buffer ):
7803
7803
def __buffer__ (self , flags : int ) -> memoryview :
7804
- return memoryview (b'' )
7804
+ return memoryview (b'' ) # pragma: no cover
7805
7805
7806
7806
self .assertIsInstance (MySubclassedBuffer (), Buffer )
7807
7807
self .assertIsSubclass (MySubclassedBuffer , Buffer )
@@ -8460,7 +8460,7 @@ def f1(a: int):
8460
8460
pass
8461
8461
8462
8462
def f2 (a : "undefined" ): # noqa: F821
8463
- pass
8463
+ pass # pragma: no cover
8464
8464
8465
8465
self .assertEqual (
8466
8466
get_annotations (f1 , format = Format .VALUE ), {"a" : int }
@@ -9360,5 +9360,5 @@ def test_sentinel_not_picklable(self):
9360
9360
pickle .dumps (sentinel )
9361
9361
9362
9362
9363
- if __name__ == '__main__' :
9363
+ if __name__ == '__main__' : # pragma: no cover
9364
9364
main ()
0 commit comments