Return ``True`` if the symbol is a parameter.
+ .. method:: is_type_parameter()
+
+ Return ``True`` if the symbol is a type parameter.
+
.. method:: is_global()
Return ``True`` if the symbol is global.
"""Interface to the compiler's internal symbol tables"""
import _symtable
-from _symtable import (USE, DEF_GLOBAL, DEF_NONLOCAL, DEF_LOCAL, DEF_PARAM,
- DEF_IMPORT, DEF_BOUND, DEF_ANNOT, SCOPE_OFF, SCOPE_MASK, FREE,
- LOCAL, GLOBAL_IMPLICIT, GLOBAL_EXPLICIT, CELL)
+from _symtable import (
+ USE,
+ DEF_GLOBAL, DEF_NONLOCAL, DEF_LOCAL,
+ DEF_PARAM, DEF_TYPE_PARAM, DEF_IMPORT, DEF_BOUND, DEF_ANNOT,
+ SCOPE_OFF, SCOPE_MASK,
+ FREE, LOCAL, GLOBAL_IMPLICIT, GLOBAL_EXPLICIT, CELL
+)
import weakref
"""Return *True* if the symbol is used in
its block.
"""
- return bool(self.__flags & _symtable.USE)
+ return bool(self.__flags & USE)
def is_parameter(self):
"""Return *True* if the symbol is a parameter.
"""
return bool(self.__flags & DEF_PARAM)
+ def is_type_parameter(self):
+ """Return *True* if the symbol is a type parameter.
+ """
+ return bool(self.__flags & DEF_TYPE_PARAM)
+
def is_global(self):
"""Return *True* if the symbol is global.
"""
"<symbol 'x': FREE, USE>")
self.assertEqual(repr(self.other_internal.lookup("some_var")),
"<symbol 'some_var': FREE, USE|DEF_NONLOCAL|DEF_LOCAL>")
+ self.assertEqual(repr(self.GenericMine.lookup("T")),
+ "<symbol 'T': LOCAL, DEF_LOCAL|DEF_TYPE_PARAM>")
def test_symtable_entry_repr(self):
expected = f"<symtable entry top({self.top.get_id()}), line {self.top.get_lineno()}>"
--- /dev/null
+Expose :meth:`symtable.Symbol.is_type_parameter` in the :mod:`symtable`
+module. Patch by Bénédikt Tran.
if (PyModule_AddIntMacro(m, DEF_NONLOCAL) < 0) return -1;
if (PyModule_AddIntMacro(m, DEF_LOCAL) < 0) return -1;
if (PyModule_AddIntMacro(m, DEF_PARAM) < 0) return -1;
+ if (PyModule_AddIntMacro(m, DEF_TYPE_PARAM) < 0) return -1;
if (PyModule_AddIntMacro(m, DEF_FREE) < 0) return -1;
if (PyModule_AddIntMacro(m, DEF_FREE_CLASS) < 0) return -1;
if (PyModule_AddIntMacro(m, DEF_IMPORT) < 0) return -1;
if (PyModule_AddIntConstant(m, "TYPE_FUNCTION", FunctionBlock) < 0)
return -1;
- if (PyModule_AddIntConstant(m, "TYPE_CLASS", ClassBlock) < 0) return -1;
+ if (PyModule_AddIntConstant(m, "TYPE_CLASS", ClassBlock) < 0)
+ return -1;
if (PyModule_AddIntConstant(m, "TYPE_MODULE", ModuleBlock) < 0)
return -1;
if (PyModule_AddIntConstant(m, "TYPE_ANNOTATION", AnnotationBlock) < 0)