MCPcopy
hub / github.com/python/mypy / get_package_properties

Method get_package_properties

mypy/moduleinspect.py:140–161  ·  view source on GitHub ↗

Return some properties of a module/package using runtime introspection. Raise InspectError if the target couldn't be imported.

(self, package_id: str)

Source from the content-addressed store, hash-verified

138 self.proc.terminate()
139
140 def get_package_properties(self, package_id: str) -> ModuleProperties:
141 """Return some properties of a module/package using runtime introspection.
142
143 Raise InspectError if the target couldn't be imported.
144 """
145 self.tasks.put(package_id)
146 res = self._get_from_queue()
147 if res is None:
148 # The process died; recover and report error.
149 self._start()
150 raise InspectError(f"Process died when importing {package_id!r}")
151 if isinstance(res, str):
152 # Error importing module
153 if self.counter > 0:
154 # Also try with a fresh process. Maybe one of the previous imports has
155 # corrupted some global state.
156 self.close()
157 self._start()
158 return self.get_package_properties(package_id)
159 raise InspectError(res)
160 self.counter += 1
161 return res
162
163 def _get_from_queue(self) -> ModuleProperties | str | None:
164 """Get value from the queue.

Callers 6

walk_packagesFunction · 0.80
test_python_moduleMethod · 0.80
test_python_packageMethod · 0.80
test_c_moduleMethod · 0.80
test_non_existentMethod · 0.80

Calls 6

_get_from_queueMethod · 0.95
_startMethod · 0.95
closeMethod · 0.95
InspectErrorClass · 0.85
isinstanceFunction · 0.85
putMethod · 0.80

Tested by 4

test_python_moduleMethod · 0.64
test_python_packageMethod · 0.64
test_c_moduleMethod · 0.64
test_non_existentMethod · 0.64