| 160 | return st |
| 161 | |
| 162 | def listdir(self, path: str) -> list[str]: |
| 163 | path = os.path.normpath(path) |
| 164 | if path in self.listdir_cache: |
| 165 | res = self.listdir_cache[path] |
| 166 | # Check the fake cache. |
| 167 | if path in self.fake_package_cache and "__init__.py" not in res: |
| 168 | res.append("__init__.py") # Updates the result as well as the cache |
| 169 | return res |
| 170 | if path in self.listdir_error_cache: |
| 171 | raise copy_os_error(self.listdir_error_cache[path]) |
| 172 | try: |
| 173 | results = os.listdir(path) |
| 174 | except OSError as err: |
| 175 | # Like above, take a copy to reduce memory use. |
| 176 | self.listdir_error_cache[path] = copy_os_error(err) |
| 177 | raise err |
| 178 | self.listdir_cache[path] = results |
| 179 | # Check the fake cache. |
| 180 | if path in self.fake_package_cache and "__init__.py" not in results: |
| 181 | results.append("__init__.py") |
| 182 | return results |
| 183 | |
| 184 | def isfile(self, path: str) -> bool: |
| 185 | st = self.stat_or_none(path) |