1010from textwrap import indent
1111import inifix
1212
13- # TODO: replace this with except* when support for Python 3.10 is dropped
14- from exceptiongroup import catch , BaseExceptionGroup
15-
1613if TYPE_CHECKING : # pragma: no cover
17- from inifix ._typing import AnyConfig # pyright: ignore[reportPrivateImportUsage]
14+ from inifix ._typing import AnyConfig
1815
1916
2017__all__ = ["app" ]
@@ -39,7 +36,7 @@ def get_cpu_count() -> int:
3936 base_cpu_count = os .process_cpu_count ()
4037 elif hasattr (os , "sched_getaffinity" ):
4138 # this function isn't available on all platforms
42- base_cpu_count = len (os .sched_getaffinity (0 )) # pyright: ignore[reportAttributeAccessIssue]
39+ base_cpu_count = len (os .sched_getaffinity (0 ))
4340 else : # pragma: no cover
4441 # this proxy is good enough in most situations
4542 base_cpu_count = os .cpu_count ()
@@ -82,19 +79,16 @@ def _validate_single_file(file: str, sections: SectionsArg) -> TaskResults:
8279 messages .append (Message (f"Error: could not find { file } " ))
8380 return TaskResults (status , messages )
8481
85- # TODO: rewrite this section with try/except*/else when support for Python 3.10 is dropped
86- def value_error_handler (exc : BaseExceptionGroup [Exception ]) -> None :
87- nonlocal status
82+ try :
83+ _ = inifix .load (file , sections = sections .value )
84+ messages .append (Message (f"Validated { file } " ))
85+ except* ValueError as exc :
8886 status = 1
8987 exc_repr = "\n " .join (str (e ) for e in exc .exceptions )
9088 messages .append (
9189 Message (f"Failed to validate { file } :\n { indent (exc_repr , ' ' )} " )
9290 )
9391
94- with catch ({ValueError : value_error_handler }):
95- _ = inifix .load (file , sections = sections .value )
96- messages .append (Message (f"Validated { file } " ))
97-
9892 return TaskResults (status , messages )
9993
10094
@@ -168,17 +162,14 @@ def _format_single_file(
168162
169163 validate_baseline : AnyConfig = {}
170164 if not skip_validation :
171- # TODO: rewrite this section with try/except* when support for Python 3.10 is dropped
172- def value_error_handler ( exc : BaseExceptionGroup [ Exception ]) -> None :
173- nonlocal status
165+ try :
166+ validate_baseline = inifix . load ( file , sections = sections . value )
167+ except* ValueError as exc :
174168 status = 1
175169 exc_repr = "\n " .join (str (e ) for e in exc .exceptions )
176170 messages .append (
177171 Message (f"Failed to format { file } :\n { indent (exc_repr , ' ' )} " )
178172 )
179-
180- with catch ({ValueError : value_error_handler }):
181- validate_baseline = inifix .load (file , sections = sections .value )
182173 if status != 0 :
183174 return TaskResults (status , messages )
184175
0 commit comments