mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
[3.13] gh-123339: Fix cases of inconsistency of __module__ and __firstlineno__ in classes (GH-123613) (#124735)
* Setting the __module__ attribute for a class now removes the
__firstlineno__ item from the type's dict.
* The _collections_abc and _pydecimal modules now completely replace the
collections.abc and decimal modules after importing them. This
allows to get the source of classes and functions defined in these
modules.
* inspect.findsource() now checks whether the first line number for a
class is out of bound.
(cherry picked from commit 69a4063ca5
)
This commit is contained in:
parent
ce0eaa6703
commit
5bf32d1300
11 changed files with 110 additions and 12 deletions
|
@ -2564,6 +2564,7 @@ class TestType(unittest.TestCase):
|
|||
self.assertEqual(A.__module__, __name__)
|
||||
self.assertEqual(A.__bases__, (object,))
|
||||
self.assertIs(A.__base__, object)
|
||||
self.assertNotIn('__firstlineno__', A.__dict__)
|
||||
x = A()
|
||||
self.assertIs(type(x), A)
|
||||
self.assertIs(x.__class__, A)
|
||||
|
@ -2642,6 +2643,17 @@ class TestType(unittest.TestCase):
|
|||
A.__qualname__ = b'B'
|
||||
self.assertEqual(A.__qualname__, 'D.E')
|
||||
|
||||
def test_type_firstlineno(self):
|
||||
A = type('A', (), {'__firstlineno__': 42})
|
||||
self.assertEqual(A.__name__, 'A')
|
||||
self.assertEqual(A.__module__, __name__)
|
||||
self.assertEqual(A.__dict__['__firstlineno__'], 42)
|
||||
A.__module__ = 'testmodule'
|
||||
self.assertEqual(A.__module__, 'testmodule')
|
||||
self.assertNotIn('__firstlineno__', A.__dict__)
|
||||
A.__firstlineno__ = 43
|
||||
self.assertEqual(A.__dict__['__firstlineno__'], 43)
|
||||
|
||||
def test_type_typeparams(self):
|
||||
class A[T]:
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue