summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorTian Gao <gaogaotiantian@hotmail.com>2023-07-24 20:12:45 (GMT)
committerGitHub <noreply@github.com>2023-07-24 20:12:45 (GMT)
commitb38370349139e06f3a44150943ee44e345567d77 (patch)
treeb1914966e580a864ba4a6e1aaa5aeebe31ae805a /Lib/inspect.py
parent8ebc9fc321ba1eeb3282c2170f351c54956893e6 (diff)
downloadcpython-b38370349139e06f3a44150943ee44e345567d77.zip
cpython-b38370349139e06f3a44150943ee44e345567d77.tar.gz
cpython-b38370349139e06f3a44150943ee44e345567d77.tar.bz2
gh-106727: Add `__module__` check for `inspect.getsource(cls)` (#106968)
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 675714d..c821183 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1078,7 +1078,8 @@ class _ClassFinder(ast.NodeVisitor):
# First, let's see if there are any method definitions
for member in self.cls.__dict__.values():
- if isinstance(member, types.FunctionType):
+ if (isinstance(member, types.FunctionType) and
+ member.__module__ == self.cls.__module__):
for lineno, end_lineno in self.lineno_found:
if lineno <= member.__code__.co_firstlineno <= end_lineno:
return lineno