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