lkj 0.1.37__tar.gz → 0.1.38__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lkj
3
- Version: 0.1.37
3
+ Version: 0.1.38
4
4
  Summary: A dump of homeless useful utils
5
5
  Home-page: https://github.com/thorwhalen/lkj
6
6
  Author: Thor Whalen
@@ -414,3 +414,34 @@ def return_error_info_on_error(
414
414
  return error_info_processor(error_info)
415
415
 
416
416
  return wrapper
417
+
418
+
419
+ from contextlib import suppress
420
+
421
+
422
+ class CallOnError(suppress):
423
+ """
424
+ An extension of the suppress context manager that enables the user to issue a warning
425
+ message when an import error occurs.
426
+
427
+ >>> warn_about_import_errors = CallOnError(ImportError, on_error=lambda err: print(f"Warning: {err}"))
428
+ >>> with warn_about_import_errors:
429
+ ... import this_package_surely_does_not_exist
430
+ Warning: No module named 'this_package_surely_does_not_exist'
431
+ >>> with warn_about_import_errors:
432
+ ... from os.this_module_does_not_exist import this_function_does_not_exist
433
+ Warning: No module named 'os.this_module_does_not_exist'; 'os' is not a package
434
+ """
435
+
436
+ def __init__(
437
+ self,
438
+ *exceptions,
439
+ on_error: Callable = print,
440
+ ):
441
+ self.on_error = on_error
442
+ super().__init__(*exceptions)
443
+
444
+ def __exit__(self, exctype, excinst, exctb):
445
+ if exctype is not None:
446
+ self.on_error(excinst)
447
+ return super().__exit__(exctype, excinst, exctb)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lkj
3
- Version: 0.1.37
3
+ Version: 0.1.38
4
4
  Summary: A dump of homeless useful utils
5
5
  Home-page: https://github.com/thorwhalen/lkj
6
6
  Author: Thor Whalen
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = lkj
3
- version = 0.1.37
3
+ version = 0.1.38
4
4
  url = https://github.com/thorwhalen/lkj
5
5
  platforms = any
6
6
  description_file = README.md
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes