Chris Reedy email@example.com writes:
Thinking about the semantics of the above, including corner cases, I find myself wanting to make the semantics of:
<some_kind_of_import_statement> in "<path>"
to be equivalent to:
sys.path.insert(0, "<path>") <some_kind_of_import_statement> del sys.path # assuming the import doesn't modify sys.path
This seems to me to be another example of the sort of setup/teardown idiom that PEP 310 was designed for:
with path_entry("<path">): import whatever
Here, we have
class path_entry def __init(self, path): self.path = path def __enter__(self): sys.path.insert(0, path) def __exit__(self): del sys.path
... and of course, path_entry might be a suitable candidate for some sort of standard library module of useful "with" idioms.
Hmm, maybe it's time to look at PEP 310 again.
This signature intentionally left blank