MCPcopy Index your code
hub / github.com/python/mypy / _fake_init

Method _fake_init

mypy/fscache.py:139–160  ·  view source on GitHub ↗

Prime the cache with a fake __init__.py file. This makes code that looks for path believe an empty file by that name exists. Should only be called after init_under_package_root() returns True.

(self, path: str)

Source from the content-addressed store, hash-verified

137 return ok
138
139 def _fake_init(self, path: str) -> os.stat_result:
140 """Prime the cache with a fake __init__.py file.
141
142 This makes code that looks for path believe an empty file by
143 that name exists. Should only be called after
144 init_under_package_root() returns True.
145 """
146 dirname, basename = os.path.split(path)
147 assert basename == "__init__.py", path
148 assert not os.path.exists(path), path # Not cached!
149 dirname = os.path.normpath(dirname)
150 st = os.stat(dirname) # May raise OSError
151 # Get stat result as a list so we can modify it.
152 seq: list[float] = list(st)
153 seq[stat.ST_MODE] = stat.S_IFREG | 0o444
154 seq[stat.ST_INO] = 1
155 seq[stat.ST_NLINK] = 1
156 seq[stat.ST_SIZE] = 0
157 st = os.stat_result(seq)
158 # Make listdir() and read() also pretend this file exists.
159 self.fake_package_cache.add(dirname)
160 return st
161
162 def listdir(self, path: str) -> list[str]:
163 path = os.path.normpath(path)

Callers 1

stat_or_noneMethod · 0.95

Calls 4

listClass · 0.85
splitMethod · 0.80
existsMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected