FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-120029: export `DEF_TYPE_PARAM` compiler flag by picnixz · Pull Request #120028 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (2) .rst  (2) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions Doc/library/symtable.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ Examining Symbol Tables

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.
Expand Down
17 changes: 13 additions & 4 deletions Lib/symtable.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""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

Expand Down Expand Up @@ -253,13 +257,18 @@ def is_referenced(self):
"""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.
"""
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_symtable.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ def test_symbol_repr(self):
"<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()}>"
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Expose :meth:`symtable.Symbol.is_type_parameter` in the :mod:`symtable`
module. Patch by Bénédikt Tran.
4 changes: 3 additions & 1 deletion Modules/symtablemodule.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ symtable_init_constants(PyObject *m)
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;
Expand All @@ -83,7 +84,8 @@ symtable_init_constants(PyObject *m)

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)
Expand Down

Back | FazBrowse Home | New Git URL