summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2024-06-20 05:27:23 (GMT)
committerGitHub <noreply@github.com>2024-06-20 05:27:23 (GMT)
commit8cfd005b6df2f1d07c0dd00450009a41796a2718 (patch)
tree67fce9c8dae1671ac8705e7d4089c9d28018d8be /Doc
parent5d194902cbe9eff0a4f974c65479046c251664fd (diff)
downloadcpython-8cfd005b6df2f1d07c0dd00450009a41796a2718.zip
cpython-8cfd005b6df2f1d07c0dd00450009a41796a2718.tar.gz
cpython-8cfd005b6df2f1d07c0dd00450009a41796a2718.tar.bz2
[3.13] gh-119698: fix `symtable.Class.get_methods` and document its behaviour correctly (GH-120151) (#120777)
(cherry picked from commit b8a8e04fec76ad7f7c3e5149114dd2ee8a5caecc) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/symtable.rst35
1 files changed, 33 insertions, 2 deletions
diff --git a/Doc/library/symtable.rst b/Doc/library/symtable.rst
index cc10265..ca7eaef 100644
--- a/Doc/library/symtable.rst
+++ b/Doc/library/symtable.rst
@@ -180,8 +180,39 @@ Examining Symbol Tables
.. method:: get_methods()
- Return a tuple containing the names of methods declared in the class.
-
+ Return a tuple containing the names of method-like functions declared
+ in the class.
+
+ Here, the term 'method' designates *any* function defined in the class
+ body via :keyword:`def` or :keyword:`async def`.
+
+ Functions defined in a deeper scope (e.g., in an inner class) are not
+ picked up by :meth:`get_methods`.
+
+ For example:
+
+ >>> import symtable
+ >>> st = symtable.symtable('''
+ ... def outer(): pass
+ ...
+ ... class A:
+ ... def f():
+ ... def w(): pass
+ ...
+ ... def g(self): pass
+ ...
+ ... @classmethod
+ ... async def h(cls): pass
+ ...
+ ... global outer
+ ... def outer(self): pass
+ ... ''', 'test', 'exec')
+ >>> class_A = st.get_children()[1]
+ >>> class_A.get_methods()
+ ('f', 'g', 'h')
+
+ Although ``A().f()`` raises :exc:`TypeError` at runtime, ``A.f`` is still
+ considered as a method-like function.
.. class:: Symbol