Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/IPython/utils/syspathcontext.py: 33%

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

18 statements  

1import sys 

2import warnings 

3 

4 

5class prepended_to_syspath: 

6 """A context for prepending a directory to sys.path for a second.""" 

7 

8 def __init__(self, dir): 

9 self.dir = dir 

10 

11 def __enter__(self): 

12 if self.dir not in sys.path: 

13 sys.path.insert(0, self.dir) 

14 self.added = True 

15 else: 

16 self.added = False 

17 

18 def __exit__(self, type, value, traceback): 

19 if self.added: 

20 try: 

21 sys.path.remove(self.dir) 

22 except ValueError: 

23 pass 

24 # Returning False causes any exceptions to be re-raised. 

25 return False