22import datetime
33import sys
44import re
5+ from typing import Callable
6+
57from ExceptionHandler .colors import Colors , Format
68from ExceptionHandler .messages import GENERIC_MESSAGES
79from TerminalPrint import TPrint
@@ -13,40 +15,40 @@ def __init__(self,
1315 trace : bool = False ,
1416 use_timestamp : bool = False ,
1517 exit_script : bool = False ,
16- print_function : callable = TPrint ().critical ,
18+ print_function : Callable = TPrint ().critical ,
1719 return_string_rather_than_print : bool = False
1820 ):
1921 # Handler defaults
2022 self .show_line : bool = show_line
2123 self .trace : bool = trace
2224 self .use_timestamp : bool = use_timestamp
2325 self .exit_script : bool = exit_script
24- self .print_function : callable = print_function
26+ self .print_function : Callable = print_function
2527 self .return_string_rather_than_print : bool = return_string_rather_than_print
2628
2729 # Formatter defaults
2830 # # Color wise
29- self .main_color : Colors = Colors .WHITE
30- self .message_color : Colors = self .main_color
31- self .trace_color : Colors = self .main_color
32- self .timestamps_color : Colors = self .main_color
31+ self .main_color : Colors | str = Colors .WHITE
32+ self .message_color : Colors | str = self .main_color
33+ self .trace_color : Colors | str = self .main_color
34+ self .timestamps_color : Colors | str = self .main_color
3335 # # Format wise
34- self .main_format : Format = Format .NORMAL
36+ self .main_format : Format | str = Format .NORMAL
3537 self .message_text_format : Format = self .main_format
3638 self .trace_text_format : Format = self .main_format
3739 self .timestamps_text_format : Format = self .main_format
3840 # # # Datetime wise
3941 self .datetime_format : str = "%Y-%m-%d %H:%M:%S"
4042
4143 def formatter (self ,
42- main_format : Format = None ,
43- timestamps_format : Format = None ,
44- trace_format : Format = None ,
45- message_format : Format = None ,
46- main_color : Colors = None ,
47- timestamps_color : Colors = None ,
48- trace_color : Colors = None ,
49- message_color : Colors = None ,
44+ main_format : Format | str = None ,
45+ timestamps_format : Format | str = None ,
46+ trace_format : Format | str = None ,
47+ message_format : Format | str = None ,
48+ main_color : Colors | str = None ,
49+ timestamps_color : Colors | str = None ,
50+ trace_color : Colors | str = None ,
51+ message_color : Colors | str = None ,
5052 datetime_format : str = None
5153 ):
5254 # Format wise
@@ -95,8 +97,9 @@ def exception(self,
9597 f"\n { self .trace_text_format } { self .trace_color } { trace_str } { Colors .RESET } "
9698 )
9799
98- if (
99- return_string_rather_than_print is None and self .return_string_rather_than_print ) or return_string_rather_than_print :
100+ if ((
101+ return_string_rather_than_print is None and self .return_string_rather_than_print )
102+ or return_string_rather_than_print ):
100103 return final_msg
101104 self .print_function (final_msg )
102105
0 commit comments