Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4bd67c5

Browse files
Coverage: exclude some noise (#656)
1 parent e589a26 commit 4bd67c5

File tree

2 files changed

+44
-40
lines changed

2 files changed

+44
-40
lines changed

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,7 @@ show_missing = true
128128
# If not explicitly omitted they will result in warnings in the report.
129129
omit = ["inspect*", "ann*"]
130130
ignore_errors = true
131+
exclude_also = [
132+
# Exclude placeholder function and class bodies.
133+
'^\s*((async )?def|class) .*:\n\s*(pass|raise NotImplementedError)',
134+
]

src/test_typing_extensions.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def h(x: int) -> int: ...
651651
@overload
652652
def h(x: str) -> str: ...
653653
def h(x):
654-
return x
654+
return x # pragma: no cover
655655

656656
overloads = get_overloads(h)
657657
self.assertEqual(len(overloads), 2)
@@ -1516,15 +1516,15 @@ def __init__(self, value):
15161516

15171517
def __await__(self) -> typing.Iterator[T_a]:
15181518
yield
1519-
return self.value
1519+
return self.value # pragma: no cover
15201520

15211521
class AsyncIteratorWrapper(AsyncIterator[T_a]):
15221522

15231523
def __init__(self, value: Iterable[T_a]):
15241524
self.value = value
15251525

15261526
def __aiter__(self) -> AsyncIterator[T_a]:
1527-
return self
1527+
return self # pragma: no cover
15281528

15291529
async def __anext__(self) -> T_a:
15301530
data = await self.value
@@ -2039,7 +2039,7 @@ class GeneratorTests(BaseTestCase):
20392039

20402040
def test_generator_basics(self):
20412041
def foo():
2042-
yield 42
2042+
yield 42 # pragma: no cover
20432043
g = foo()
20442044

20452045
self.assertIsInstance(g, typing_extensions.Generator)
@@ -2097,7 +2097,7 @@ def g(): yield 0
20972097

20982098
def test_async_generator_basics(self):
20992099
async def f():
2100-
yield 42
2100+
yield 42 # pragma: no cover
21012101
g = f()
21022102

21032103
self.assertIsInstance(g, typing_extensions.AsyncGenerator)
@@ -2216,7 +2216,7 @@ class OtherABCTests(BaseTestCase):
22162216
def test_contextmanager(self):
22172217
@contextlib.contextmanager
22182218
def manager():
2219-
yield 42
2219+
yield 42 # pragma: no cover
22202220

22212221
cm = manager()
22222222
self.assertIsInstance(cm, typing_extensions.ContextManager)
@@ -2235,7 +2235,7 @@ class NotACM:
22352235
self.assertNotIsInstance(NotACM(), typing_extensions.AsyncContextManager)
22362236
@contextlib.contextmanager
22372237
def manager():
2238-
yield 42
2238+
yield 42 # pragma: no cover
22392239

22402240
cm = manager()
22412241
self.assertNotIsInstance(cm, typing_extensions.AsyncContextManager)
@@ -2614,7 +2614,7 @@ class B(P):
26142614
pass
26152615
class C(B):
26162616
def ameth(self) -> int:
2617-
return 26
2617+
return 26 # pragma: no cover
26182618
with self.assertRaises(TypeError):
26192619
B()
26202620
self.assertIsInstance(C(), P)
@@ -3032,11 +3032,11 @@ def test_protocols_isinstance_properties_and_descriptors(self):
30323032
class C:
30333033
@property
30343034
def attr(self):
3035-
return 42
3035+
return 42 # pragma: no cover
30363036

30373037
class CustomDescriptor:
30383038
def __get__(self, obj, objtype=None):
3039-
return 42
3039+
return 42 # pragma: no cover
30403040

30413041
class D:
30423042
attr = CustomDescriptor()
@@ -3120,11 +3120,11 @@ class HasX(Protocol):
31203120
class CustomDirWithX:
31213121
x = 10
31223122
def __dir__(self):
3123-
return []
3123+
return [] # pragma: no cover
31243124

31253125
class CustomDirWithoutX:
31263126
def __dir__(self):
3127-
return ["x"]
3127+
return ["x"] # pragma: no cover
31283128

31293129
self.assertIsInstance(CustomDirWithX(), HasX)
31303130
self.assertNotIsInstance(CustomDirWithoutX(), HasX)
@@ -3133,11 +3133,11 @@ def test_protocols_isinstance_attribute_access_with_side_effects(self):
31333133
class C:
31343134
@property
31353135
def attr(self):
3136-
raise AttributeError('no')
3136+
raise AttributeError('no') # pragma: no cover
31373137

31383138
class CustomDescriptor:
31393139
def __get__(self, obj, objtype=None):
3140-
raise RuntimeError("NO")
3140+
raise RuntimeError("NO") # pragma: no cover
31413141

31423142
class D:
31433143
attr = CustomDescriptor()
@@ -3149,7 +3149,7 @@ class F(D): ...
31493149

31503150
class WhyWouldYouDoThis:
31513151
def __getattr__(self, name):
3152-
raise RuntimeError("wut")
3152+
raise RuntimeError("wut") # pragma: no cover
31533153

31543154
T = TypeVar('T')
31553155

@@ -3220,7 +3220,7 @@ class C:
32203220
def __init__(self, attr):
32213221
self.attr = attr
32223222
def meth(self, arg):
3223-
return 0
3223+
return 0 # pragma: no cover
32243224
class Bad: pass
32253225
self.assertIsInstance(APoint(1, 2, 'A'), Point)
32263226
self.assertIsInstance(BPoint(1, 2), Point)
@@ -3491,7 +3491,7 @@ class ImplementsHasX:
34913491
class NotRuntimeCheckable(Protocol):
34923492
@classmethod
34933493
def __subclasshook__(cls, other):
3494-
return hasattr(other, 'x')
3494+
return hasattr(other, 'x') # pragma: no cover
34953495

34963496
must_be_runtime_checkable = (
34973497
"Instance and class checks can only be used "
@@ -3577,7 +3577,7 @@ class PSub(P1[str], Protocol):
35773577
class Test:
35783578
x = 1
35793579
def bar(self, x: str) -> str:
3580-
return x
3580+
return x # pragma: no cover
35813581
self.assertIsInstance(Test(), PSub)
35823582
if not TYPING_3_10_0:
35833583
with self.assertRaises(TypeError):
@@ -3765,9 +3765,9 @@ def close(self): pass
37653765
class A: ...
37663766
class B:
37673767
def __iter__(self):
3768-
return []
3768+
return [] # pragma: no cover
37693769
def close(self):
3770-
return 0
3770+
return 0 # pragma: no cover
37713771

37723772
self.assertIsSubclass(B, Custom)
37733773
self.assertNotIsSubclass(A, Custom)
@@ -3785,7 +3785,7 @@ def __release_buffer__(self, mv: memoryview) -> None: ...
37853785
class C: pass
37863786
class D:
37873787
def __buffer__(self, flags: int) -> memoryview:
3788-
return memoryview(b'')
3788+
return memoryview(b'') # pragma: no cover
37893789
def __release_buffer__(self, mv: memoryview) -> None:
37903790
pass
37913791

@@ -3811,7 +3811,7 @@ def __release_buffer__(self, mv: memoryview) -> None: ...
38113811
class C: pass
38123812
class D:
38133813
def __buffer__(self, flags: int) -> memoryview:
3814-
return memoryview(b'')
3814+
return memoryview(b'') # pragma: no cover
38153815
def __release_buffer__(self, mv: memoryview) -> None:
38163816
pass
38173817

@@ -4095,7 +4095,7 @@ class Vec2D(Protocol):
40954095
y: float
40964096

40974097
def square_norm(self) -> float:
4098-
return self.x ** 2 + self.y ** 2
4098+
return self.x ** 2 + self.y ** 2 # pragma: no cover
40994099

41004100
self.assertEqual(Vec2D.__protocol_attrs__, {'x', 'y', 'square_norm'})
41014101
expected_error_message = (
@@ -4108,7 +4108,7 @@ def square_norm(self) -> float:
41084108
def test_nonruntime_protocol_interaction_with_evil_classproperty(self):
41094109
class classproperty:
41104110
def __get__(self, instance, type):
4111-
raise RuntimeError("NO")
4111+
raise RuntimeError("NO") # pragma: no cover
41124112

41134113
class Commentable(Protocol):
41144114
evil = classproperty()
@@ -4155,23 +4155,23 @@ class SpecificProtocolTests(BaseTestCase):
41554155
def test_reader_runtime_checkable(self):
41564156
class MyReader:
41574157
def read(self, n: int) -> bytes:
4158-
return b""
4158+
return b"" # pragma: no cover
41594159

41604160
class WrongReader:
41614161
def readx(self, n: int) -> bytes:
4162-
return b""
4162+
return b"" # pragma: no cover
41634163

41644164
self.assertIsInstance(MyReader(), typing_extensions.Reader)
41654165
self.assertNotIsInstance(WrongReader(), typing_extensions.Reader)
41664166

41674167
def test_writer_runtime_checkable(self):
41684168
class MyWriter:
41694169
def write(self, b: bytes) -> int:
4170-
return 0
4170+
return 0 # pragma: no cover
41714171

41724172
class WrongWriter:
41734173
def writex(self, b: bytes) -> int:
4174-
return 0
4174+
return 0 # pragma: no cover
41754175

41764176
self.assertIsInstance(MyWriter(), typing_extensions.Writer)
41774177
self.assertNotIsInstance(WrongWriter(), typing_extensions.Writer)
@@ -5959,7 +5959,7 @@ def run():
59595959
proc = subprocess.run(
59605960
[sys.executable, "-c", code], check=True, capture_output=True, text=True,
59615961
)
5962-
except subprocess.CalledProcessError as exc:
5962+
except subprocess.CalledProcessError as exc: # pragma: no cover
59635963
print("stdout", exc.stdout, sep="\n")
59645964
print("stderr", exc.stderr, sep="\n")
59655965
raise
@@ -6324,7 +6324,7 @@ def test_alias(self):
63246324
StringTuple = Tuple[LiteralString, LiteralString]
63256325
class Alias:
63266326
def return_tuple(self) -> StringTuple:
6327-
return ("foo", "pep" + "675")
6327+
return ("foo", "pep" + "675") # pragma: no cover
63286328

63296329
def test_typevar(self):
63306330
StrT = TypeVar("StrT", bound=LiteralString)
@@ -6375,7 +6375,7 @@ def test_alias(self):
63756375
TupleSelf = Tuple[Self, Self]
63766376
class Alias:
63776377
def return_tuple(self) -> TupleSelf:
6378-
return (self, self)
6378+
return (self, self) # pragma: no cover
63796379

63806380
def test_pickle(self):
63816381
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
@@ -6615,7 +6615,7 @@ class Wrapper:
66156615
def __init__(self, func):
66166616
self.func = func
66176617
def __call__(self, *args, **kwargs):
6618-
return self.func(*args, **kwargs)
6618+
return self.func(*args, **kwargs) # pragma: no cover
66196619

66206620
# Check that no error is thrown if the attribute
66216621
# is not writable.
@@ -6899,7 +6899,7 @@ def test_typing_extensions_compiles_with_opt(self):
68996899
subprocess.check_output(f'{sys.executable} -OO {file_path}',
69006900
stderr=subprocess.STDOUT,
69016901
shell=True)
6902-
except subprocess.CalledProcessError:
6902+
except subprocess.CalledProcessError: # pragma: no cover
69036903
self.fail('Module does not compile with optimize=2 (-OO flag).')
69046904

69056905

@@ -6989,13 +6989,13 @@ def test_annotation_usage_with_methods(self):
69896989
class XMethBad(NamedTuple):
69906990
x: int
69916991
def _fields(self):
6992-
return 'no chance for this'
6992+
return 'no chance for this' # pragma: no cover
69936993

69946994
with self.assertRaisesRegex(AttributeError, bad_overwrite_error_message):
69956995
class XMethBad2(NamedTuple):
69966996
x: int
69976997
def _source(self):
6998-
return 'no chance for this as well'
6998+
return 'no chance for this as well' # pragma: no cover
69996999

70007000
def test_multiple_inheritance(self):
70017001
class A:
@@ -7660,7 +7660,7 @@ def test_generic_with_broken_eq(self):
76607660
class BrokenEq(type):
76617661
def __eq__(self, other):
76627662
if other is typing_extensions.Protocol:
7663-
raise TypeError("I'm broken")
7663+
raise TypeError("I'm broken") # pragma: no cover
76647664
return False
76657665

76667666
class G(Generic[T], metaclass=BrokenEq):
@@ -7786,7 +7786,7 @@ def test(self):
77867786

77877787
class MyRegisteredBuffer:
77887788
def __buffer__(self, flags: int) -> memoryview:
7789-
return memoryview(b'')
7789+
return memoryview(b'') # pragma: no cover
77907790

77917791
# On 3.12, collections.abc.Buffer does a structural compatibility check
77927792
if TYPING_3_12_0:
@@ -7801,7 +7801,7 @@ def __buffer__(self, flags: int) -> memoryview:
78017801

78027802
class MySubclassedBuffer(Buffer):
78037803
def __buffer__(self, flags: int) -> memoryview:
7804-
return memoryview(b'')
7804+
return memoryview(b'') # pragma: no cover
78057805

78067806
self.assertIsInstance(MySubclassedBuffer(), Buffer)
78077807
self.assertIsSubclass(MySubclassedBuffer, Buffer)
@@ -8460,7 +8460,7 @@ def f1(a: int):
84608460
pass
84618461

84628462
def f2(a: "undefined"): # noqa: F821
8463-
pass
8463+
pass # pragma: no cover
84648464

84658465
self.assertEqual(
84668466
get_annotations(f1, format=Format.VALUE), {"a": int}
@@ -9360,5 +9360,5 @@ def test_sentinel_not_picklable(self):
93609360
pickle.dumps(sentinel)
93619361

93629362

9363-
if __name__ == '__main__':
9363+
if __name__ == '__main__': # pragma: no cover
93649364
main()

0 commit comments

Comments
 (0)