File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed
Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 1+ from __future__ import annotations
12from enum import Enum
3+ import typing as t
24import warnings
35
46import colorama # type: ignore
@@ -14,7 +16,25 @@ class Level(Enum):
1416
1517
1618def colored_warning (
17- message : str , stacklevel : int = 3 , level : Level = Level .medium
19+ message : str ,
20+ category : t .Type [Warning ] = Warning ,
21+ stacklevel : int = 3 ,
22+ level : Level = Level .medium ,
1823):
24+ """
25+ A wrapper around the stdlib's `warnings.warn`, which colours the output.
26+
27+ :param message:
28+ The message to display to the user
29+ :category:
30+ `Warning` has several subclasses which may be more appropriate, for
31+ example `DeprecationWarning`.
32+ :stacklevel:
33+ Used to determine there the source of the error within the source code.
34+ See the Python docs for more detail.
35+ https://docs.python.org/3/library/warnings.html#warnings.warn
36+ :level:
37+ Used to determine the colour of the text displayed to the user.
38+ """
1939 colored_message = level .value + message + colorama .Fore .RESET
20- warnings .warn (colored_message , stacklevel = stacklevel )
40+ warnings .warn (colored_message , category = category , stacklevel = stacklevel )
You can’t perform that action at this time.
0 commit comments