mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
Match __module__ setter behavior to CPython (#7424)
* Remove stale __firstlineno__ when updating type.__module__ * Register and use __firstlineno__ as identifier
This commit is contained in:
1 parent
ae73aab6a4
commit
257cf6fa0e
4 files changed
+4
-5
No files matched your search
Vendored
-1
@@ -2939,7 +2939,6 @@ class TestType(unittest.TestCase):
|
||||
A.__qualname__ = b'B'
|
||||
self.assertEqual(A.__qualname__, 'D.E')
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: '__firstlineno__' unexpectedly found in mappingproxy({'__firstlineno__': 42, '__module__': 'testmodule', '__dict__': <attribute '__dict__' of 'A' objects>, '__doc__': None})
|
||||
def test_type_firstlineno(self):
|
||||
A = type('A', (), {'__firstlineno__': 42})
|
||||
self.assertEqual(A.__name__, 'A')
|
||||
|
||||
-1
@@ -910,7 +910,6 @@ class TestGetsourceStdlib(unittest.TestCase):
|
||||
self.assertRaises(OSError, inspect.getsource, tomllib.TOMLDecodeError)
|
||||
self.assertRaises(OSError, inspect.getsourcelines, tomllib.TOMLDecodeError)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: OSError not raised by getsource
|
||||
def test_getsource_stdlib_abc(self):
|
||||
# Pure Python implementation
|
||||
abc = import_helper.import_fresh_module('abc', blocked=['_abc'])
|
||||
|
||||
@@ -1648,9 +1648,9 @@ impl PyType {
|
||||
#[pygetset(setter)]
|
||||
fn set___module__(&self, value: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
|
||||
self.check_set_special_type_attr(identifier!(vm, __module__), vm)?;
|
||||
self.attributes
|
||||
.write()
|
||||
.insert(identifier!(vm, __module__), value);
|
||||
let mut attributes = self.attributes.write();
|
||||
attributes.swap_remove(identifier!(vm, __firstlineno__));
|
||||
attributes.insert(identifier!(vm, __module__), value);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +135,7 @@ declare_const_name! {
|
||||
__eq__,
|
||||
__exit__,
|
||||
__file__,
|
||||
__firstlineno__,
|
||||
__float__,
|
||||
__floor__,
|
||||
__floordiv__,
|
||||
|
||||
Reference in new issue
Block a user