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

Class PythonAttribute

src/twisted/python/modules.py:242–296  ·  view source on GitHub ↗

I represent a function, class, or other object that is present. @ivar name: the fully-qualified python name of this attribute. @ivar onObject: a reference to a PythonModule or other PythonAttribute that is this attribute's logical parent. @ivar name: the fully qualified pytho

Source from the content-addressed store, hash-verified

240
241
242class PythonAttribute:
243 """
244 I represent a function, class, or other object that is present.
245
246 @ivar name: the fully-qualified python name of this attribute.
247
248 @ivar onObject: a reference to a PythonModule or other PythonAttribute that
249 is this attribute's logical parent.
250
251 @ivar name: the fully qualified python name of the attribute represented by
252 this class.
253 """
254
255 def __init__(
256 self, name: str, onObject: PythonAttribute, loaded: bool, pythonValue: object
257 ) -> None:
258 """
259 Create a PythonAttribute. This is a private constructor. Do not construct
260 me directly, use PythonModule.iterAttributes.
261
262 @param name: the FQPN
263 @param onObject: see ivar
264 @param loaded: always True, for now
265 @param pythonValue: the value of the attribute we're pointing to.
266 """
267 self.name: str = name
268 self.onObject = onObject
269 self._loaded = loaded
270 self.pythonValue = pythonValue
271
272 def __repr__(self) -> str:
273 return f"PythonAttribute<{self.name!r}>"
274
275 def isLoaded(self):
276 """
277 Return a boolean describing whether the attribute this describes has
278 actually been loaded into memory by importing its module.
279
280 Note: this currently always returns true; there is no Python parser
281 support in this module yet.
282 """
283 return self._loaded
284
285 def load(self, default=_nothing):
286 """
287 Load the value associated with this attribute.
288
289 @return: an arbitrary Python object, or 'default' if there is an error
290 loading it.
291 """
292 return self.pythonValue
293
294 def iterAttributes(self):
295 for name, val in inspect.getmembers(self.load()):
296 yield PythonAttribute(self.name + "." + name, self, True, val)
297
298
299class PythonModule(_ModuleIteratorHelper):

Callers 2

iterAttributesMethod · 0.85
iterAttributesMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected