summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_inspect
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-05-06 09:02:37 (GMT)
committerGitHub <noreply@github.com>2024-05-06 09:02:37 (GMT)
commit153b3f75306b5d26e29ea157105d0fdc247ef853 (patch)
treef73ede56af175d27698ef56bec21073f98889bbc /Lib/test/test_inspect
parent716ec4bfcf1a564db9936122c442baa99f9c4a8c (diff)
downloadcpython-153b3f75306b5d26e29ea157105d0fdc247ef853.zip
cpython-153b3f75306b5d26e29ea157105d0fdc247ef853.tar.gz
cpython-153b3f75306b5d26e29ea157105d0fdc247ef853.tar.bz2
gh-118465: Add __firstlineno__ attribute to class (GH-118475)
It is set by compiler with the line number of the first line of the class definition.
Diffstat (limited to 'Lib/test/test_inspect')
-rw-r--r--Lib/test/test_inspect/test_inspect.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py
index d122403..82e466e 100644
--- a/Lib/test/test_inspect/test_inspect.py
+++ b/Lib/test/test_inspect/test_inspect.py
@@ -817,6 +817,21 @@ class TestRetrievingSourceCode(GetSourceBase):
def test_getsource_on_code_object(self):
self.assertSourceEqual(mod.eggs.__code__, 12, 18)
+ def test_getsource_on_generated_class(self):
+ A = type('A', (), {})
+ self.assertEqual(inspect.getsourcefile(A), __file__)
+ self.assertEqual(inspect.getfile(A), __file__)
+ self.assertIs(inspect.getmodule(A), sys.modules[__name__])
+ self.assertRaises(OSError, inspect.getsource, A)
+ self.assertRaises(OSError, inspect.getsourcelines, A)
+ self.assertIsNone(inspect.getcomments(A))
+
+ def test_getsource_on_class_without_firstlineno(self):
+ __firstlineno__ = 1
+ class C:
+ nonlocal __firstlineno__
+ self.assertRaises(OSError, inspect.getsource, C)
+
class TestGetsourceInteractive(unittest.TestCase):
def test_getclasses_interactive(self):
# bpo-44648: simulate a REPL session;