summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>2024-06-12 11:14:50 (GMT)
committerGitHub <noreply@github.com>2024-06-12 11:14:50 (GMT)
commit755dab719dfc924dd8aef46f67512dabb8f25071 (patch)
treeb79b7cba8128b9d90c5646f2c589de1fdeeb056b /Doc
parent7dd8c37a067f9fcb6a2a658d6a93b294cc2e6fb4 (diff)
downloadcpython-755dab719dfc924dd8aef46f67512dabb8f25071.zip
cpython-755dab719dfc924dd8aef46f67512dabb8f25071.tar.gz
cpython-755dab719dfc924dd8aef46f67512dabb8f25071.tar.bz2
gh-120029: make `symtable.Symbol.__repr__` correctly reflect the compiler's flags, add methods (#120099)
Expose :class:`symtable.Symbol` methods :meth:`~symtable.Symbol.is_free_class`, :meth:`~symtable.Symbol.is_comp_iter` and :meth:`~symtable.Symbol.is_comp_cell`. --------- Co-authored-by: Carl Meyer <carl@oddbird.net>
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/symtable.rst34
-rw-r--r--Doc/whatsnew/3.14.rst11
2 files changed, 45 insertions, 0 deletions
diff --git a/Doc/library/symtable.rst b/Doc/library/symtable.rst
index e17a33f..050a941 100644
--- a/Doc/library/symtable.rst
+++ b/Doc/library/symtable.rst
@@ -155,6 +155,8 @@ Examining Symbol Tables
Return ``True`` if the symbol is a type parameter.
+ .. versionadded:: 3.14
+
.. method:: is_global()
Return ``True`` if the symbol is global.
@@ -182,10 +184,42 @@ Examining Symbol Tables
Return ``True`` if the symbol is referenced in its block, but not assigned
to.
+ .. method:: is_free_class()
+
+ Return *True* if a class-scoped symbol is free from
+ the perspective of a method.
+
+ Consider the following example::
+
+ def f():
+ x = 1 # function-scoped
+ class C:
+ x = 2 # class-scoped
+ def method(self):
+ return x
+
+ In this example, the class-scoped symbol ``x`` is considered to
+ be free from the perspective of ``C.method``, thereby allowing
+ the latter to return *1* at runtime and not *2*.
+
+ .. versionadded:: 3.14
+
.. method:: is_assigned()
Return ``True`` if the symbol is assigned to in its block.
+ .. method:: is_comp_iter()
+
+ Return ``True`` if the symbol is a comprehension iteration variable.
+
+ .. versionadded:: 3.14
+
+ .. method:: is_comp_cell()
+
+ Return ``True`` if the symbol is a cell in an inlined comprehension.
+
+ .. versionadded:: 3.14
+
.. method:: is_namespace()
Return ``True`` if name binding introduces new namespace.
diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst
index b77ff30..b357553 100644
--- a/Doc/whatsnew/3.14.rst
+++ b/Doc/whatsnew/3.14.rst
@@ -100,6 +100,17 @@ os
by :func:`os.unsetenv`, or made outside Python in the same process.
(Contributed by Victor Stinner in :gh:`120057`.)
+symtable
+--------
+
+* Expose the following :class:`symtable.Symbol` methods:
+
+ * :meth:`~symtable.Symbol.is_free_class`
+ * :meth:`~symtable.Symbol.is_comp_iter`
+ * :meth:`~symtable.Symbol.is_comp_cell`
+
+ (Contributed by Bénédikt Tran in :gh:`120029`.)
+
Optimizations
=============