MCPcopy Index your code
hub / github.com/RustPython/RustPython / Symbol

Class Symbol

Lib/symtable.py:283–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281
282
283class Symbol:
284
285 def __init__(self, name, flags, namespaces=None, *, module_scope=False):
286 self.__name = name
287 self.__flags = flags
288 self.__scope = _get_scope(flags)
289 self.__namespaces = namespaces or ()
290 self.__module_scope = module_scope
291
292 def __repr__(self):
293 flags_str = '|'.join(self._flags_str())
294 return f'<symbol {self.__name!r}: {self._scope_str()}, {flags_str}>'
295
296 def _scope_str(self):
297 return _scopes_value_to_name.get(self.__scope) or str(self.__scope)
298
299 def _flags_str(self):
300 for flagname, flagvalue in _flags:
301 if self.__flags & flagvalue == flagvalue:
302 yield flagname
303
304 def get_name(self):
305 """Return a name of a symbol.
306 """
307 return self.__name
308
309 def is_referenced(self):
310 """Return *True* if the symbol is used in
311 its block.
312 """
313 return bool(self.__flags & USE)
314
315 def is_parameter(self):
316 """Return *True* if the symbol is a parameter.
317 """
318 return bool(self.__flags & DEF_PARAM)
319
320 def is_type_parameter(self):
321 """Return *True* if the symbol is a type parameter.
322 """
323 return bool(self.__flags & DEF_TYPE_PARAM)
324
325 def is_global(self):
326 """Return *True* if the symbol is global.
327 """
328 return bool(self.__scope in (GLOBAL_IMPLICIT, GLOBAL_EXPLICIT)
329 or (self.__module_scope and self.__flags & DEF_BOUND))
330
331 def is_nonlocal(self):
332 """Return *True* if the symbol is nonlocal."""
333 return bool(self.__flags & DEF_NONLOCAL)
334
335 def is_declared_global(self):
336 """Return *True* if the symbol is declared global
337 with a global statement."""
338 return bool(self.__scope == GLOBAL_EXPLICIT)
339
340 def is_local(self):

Callers 1

lookupMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected