MCPcopy Index your code
hub / github.com/python/cpython / TemporaryPyFile

Class TemporaryPyFile

Lib/test/test_tabnanny.py:64–80  ·  view source on GitHub ↗

Create a temporary python source code file.

Source from the content-addressed store, hash-verified

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

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…