File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change 88class OSProxy (types .ModuleType ):
99 """Proxy module to intercept os attribute access."""
1010 overrides = {}
11+
1112 def __init__ (self , real_os ):
1213 super ().__init__ ("os" )
1314 self ._real_os = real_os
@@ -23,6 +24,7 @@ def __dir__(self):
2324 def register_override (cls , name , value ):
2425 cls .overrides [name ] = value
2526
27+
2628class OSFinder (importlib .abc .MetaPathFinder ):
2729 """Meta path finder to intercept imports of 'os' and return our proxy."""
2830 def find_spec (self , fullname , path , target = None ):
Original file line number Diff line number Diff line change 5050_contextes = {'' : {}}
5151_curr_context = ''
5252
53- def set_context (context_name , context = {}):
53+
54+ def set_context (context_name , context = None ):
5455 """
5556 Set context for tracking environment changes.
5657 """
@@ -63,6 +64,7 @@ def set_context(context_name, context = {}):
6364 context = {}
6465 _contextes [context_name ] = context
6566
67+
6668def get_context ():
6769 """
6870 Return current context for tracking environment changes.
@@ -95,7 +97,8 @@ def get_changes():
9597 """
9698 return get_context ()
9799
98- def apply_context (context = None ):
100+
101+ def apply_context (context = None ):
99102 """Return the current environment with the changes tracked in the context applied.
100103
101104 Args:
@@ -127,8 +130,10 @@ def with_environment(copy_current=False):
127130 # Get a key that does not exist in _contextes
128131 base = '_context_'
129132 cnt = 0
130- while (context := f"{ base } { cnt } " ) in _contextes :
133+ context = f"{ base } { cnt } "
134+ while context in _contextes :
131135 cnt += 1
136+ context = f"{ base } { cnt } "
132137
133138 prev_context = _curr_context
134139 kwargs = {}
You can’t perform that action at this time.
0 commit comments