MCPcopy Index your code
hub / github.com/RustPython/RustPython / TemporaryPyFile

Class TemporaryPyFile

Lib/test/test_tabnanny.py:65–81  ·  view source on GitHub ↗

Create a temporary python source code file.

Source from the content-addressed store, hash-verified

63
64
65class TemporaryPyFile:
66 """Create a temporary python source code file."""
67
68 def __init__(self, source_code='', directory=None):
69 self.source_code = source_code
70 self.dir = directory
71
72 def __enter__(self):
73 with tempfile.NamedTemporaryFile(
74 mode='w', dir=self.dir, suffix=".py", delete=False
75 ) as f:
76 f.write(self.source_code)
77 self.file_path = f.name
78 return self.file_path
79
80 def __exit__(self, exc_type, exc_value, exc_traceback):
81 unlink(self.file_path)
82
83
84class TestFormatWitnesses(TestCase):

Calls

no outgoing calls