MCPcopy Create free account
hub / github.com/twisted/twisted / PythonModule

Class PythonModule

src/twisted/python/modules.py:299–437  ·  view source on GitHub ↗

Representation of a module which could be imported from sys.path. @ivar name: the fully qualified python name of this module. @ivar filePath: a FilePath-like object which points to the location of this module. @ivar pathEntry: a L{PathEntry} instance which this module was loc

Source from the content-addressed store, hash-verified

297
298
299class PythonModule(_ModuleIteratorHelper):
300 """
301 Representation of a module which could be imported from sys.path.
302
303 @ivar name: the fully qualified python name of this module.
304
305 @ivar filePath: a FilePath-like object which points to the location of this
306 module.
307
308 @ivar pathEntry: a L{PathEntry} instance which this module was located
309 from.
310 """
311
312 def __init__(
313 self, name: str, filePath: FilePath[str], pathEntry: PathEntry
314 ) -> None:
315 """
316 Create a PythonModule. Do not construct this directly, instead inspect a
317 PythonPath or other PythonModule instances.
318
319 @param name: see ivar
320 @param filePath: see ivar
321 @param pathEntry: see ivar
322 """
323 _name = nativeString(name)
324 assert not _name.endswith(".__init__")
325 self.name: str = _name
326 self.filePath = filePath
327 self.parentPath = filePath.parent()
328 self.pathEntry = pathEntry
329
330 def _getEntry(self):
331 return self.pathEntry
332
333 def __repr__(self) -> str:
334 """
335 Return a string representation including the module name.
336 """
337 return f"PythonModule<{self.name!r}>"
338
339 def isLoaded(self):
340 """
341 Determine if the module is loaded into sys.modules.
342
343 @return: a boolean: true if loaded, false if not.
344 """
345 return self.pathEntry.pythonPath.moduleDict.get(self.name) is not None
346
347 def iterAttributes(self):
348 """
349 List all the attributes defined in this module.
350
351 Note: Future work is planned here to make it possible to list python
352 attributes on a module without loading the module by inspecting ASTs or
353 bytecode, but currently any iteration of PythonModule objects insists
354 they must be loaded, and will use inspect.getmodule.
355
356 @raise NotImplementedError: if this module is not loaded.

Callers 2

iterModulesMethod · 0.85
__getitem__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected