Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/argcomplete/io.py: 46%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

26 statements  

1import contextlib 

2import os 

3import sys 

4 

5_DEBUG = "_ARC_DEBUG" in os.environ 

6 

7debug_stream = sys.stderr 

8 

9 

10def debug(*args): 

11 if _DEBUG: 

12 print(file=debug_stream, *args) 

13 

14 

15@contextlib.contextmanager 

16def mute_stdout(): 

17 stdout = sys.stdout 

18 sys.stdout = open(os.devnull, "w") 

19 try: 

20 yield 

21 finally: 

22 sys.stdout = stdout 

23 

24 

25@contextlib.contextmanager 

26def mute_stderr(): 

27 stderr = sys.stderr 

28 sys.stderr = open(os.devnull, "w") 

29 try: 

30 yield 

31 finally: 

32 sys.stderr.close() 

33 sys.stderr = stderr 

34 

35 

36def warn(*args): 

37 """ 

38 Prints **args** to standard error when running completions. This will interrupt the user's command line interaction; 

39 use it to indicate an error condition that is preventing your completer from working. 

40 """ 

41 print(file=debug_stream) 

42 print(file=debug_stream, *args)