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

Class InspectionStubGenerator

mypy/stubgenc.py:219–920  ·  view source on GitHub ↗

Stub generator that does not parse code. Generation is performed by inspecting the module's contents, and thus works for highly dynamic modules, pyc files, and C modules (via the CStubGenerator subclass).

Source from the content-addressed store, hash-verified

217
218
219class InspectionStubGenerator(BaseStubGenerator):
220 """Stub generator that does not parse code.
221
222 Generation is performed by inspecting the module's contents, and thus works
223 for highly dynamic modules, pyc files, and C modules (via the CStubGenerator
224 subclass).
225 """
226
227 def __init__(
228 self,
229 module_name: str,
230 known_modules: list[str],
231 doc_dir: str = "",
232 _all_: list[str] | None = None,
233 include_private: bool = False,
234 export_less: bool = False,
235 include_docstrings: bool = False,
236 module: ModuleType | None = None,
237 ) -> None:
238 self.doc_dir = doc_dir
239 if module is None:
240 self.module = importlib.import_module(module_name)
241 else:
242 self.module = module
243 self.is_c_module = is_c_module(self.module)
244 self.known_modules = known_modules
245 self.resort_members = self.is_c_module
246 super().__init__(_all_, include_private, export_less, include_docstrings)
247 self.module_name = module_name
248 if self.is_c_module:
249 # Add additional implicit imports.
250 # C-extensions are given more latitude since they do not import the typing module.
251 self.known_imports.update(
252 {
253 "typing": [
254 "Any",
255 "Callable",
256 "ClassVar",
257 "Dict",
258 "Iterable",
259 "Iterator",
260 "List",
261 "Literal",
262 "NamedTuple",
263 "Optional",
264 "Tuple",
265 "Union",
266 ]
267 }
268 )
269
270 def get_default_function_sig(self, func: object, ctx: FunctionContext) -> FunctionSig:
271 argspec = None
272 if not self.is_c_module:
273 # Get the full argument specification of the function
274 try:
275 argspec = inspect.getfullargspec(func)
276 except TypeError:

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…