-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
_errorpep484noreturn.py
45 lines (38 loc) · 1.81 KB
/
_errorpep484noreturn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
# --------------------( LICENSE )--------------------
# Copyright (c) 2014-2021 Beartype authors.
# See "LICENSE" for further details.
'''
Project-wide :pep:`484`-compliant :attr:`typing.NoReturn` **type hint exception
raisers** (i.e., functions raising human-readable exceptions called by
:mod:`beartype`-decorated callables on the first invalid parameter or return
value failing a type-check against the :pep:`484`-compliant
:attr:`typing.NoReturn` type hint annotating that parameter or return).
This private submodule is *not* intended for importation by downstream callers.
'''
# ....................{ IMPORTS }....................
from beartype._decor._error._errorsleuth import CauseSleuth
from beartype._data.hint.pep.sign.datapepsigns import HintSignNoReturn
from beartype._util.text.utiltextlabel import label_callable
# See the "beartype.cave" submodule for further commentary.
__all__ = ['STAR_IMPORTS_CONSIDERED_HARMFUL']
# ....................{ GETTERS }....................
def get_cause_or_none_noreturn(sleuth: CauseSleuth) -> str:
'''
Human-readable string describing the failure of the decorated callable to
*not* return a value in violation of the :pep:`484`-compliant
:attr:`typing.NoReturn` type hint.
Parameters
----------
sleuth : CauseSleuth
Type-checking error cause sleuth.
'''
assert isinstance(sleuth, CauseSleuth), f'{repr(sleuth)} not cause sleuth.'
assert sleuth.hint_sign is HintSignNoReturn, (
f'{repr(sleuth.hint)} not HintSignNoReturn.')
# Return a substring describing this failure intended to be embedded in a
# longer string.
return (
f'"NoReturn"-annotated {label_callable(sleuth.func)} '
f'returned {sleuth.pith}'
)