Skip to content

Commit e34198f

Browse files
authored
Remove HEAPTYPE flag from builtins.
1 parent 3c77d14 commit e34198f

File tree

7 files changed

+22
-8
lines changed

7 files changed

+22
-8
lines changed

Lib/test/test_ast.py

+2
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ def test_no_fields(self):
565565
x = ast.Sub()
566566
self.assertEqual(x._fields, ())
567567

568+
# TODO: RUSTPYTHON _ast classes should be HEAPTYPES (except for _ast.AST)
569+
@unittest.expectedFailure
568570
def test_pickling(self):
569571
import pickle
570572
mods = [pickle]

Lib/test/test_collections.py

-2
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,6 @@ def test_odd_sizes(self):
491491
self.assertEqual(b2, tuple(b2_expected))
492492
self.assertEqual(b._fields, tuple(names))
493493

494-
# TODO: RUSTPYTHON
495-
@unittest.expectedFailure
496494
def test_pickle(self):
497495
p = TestNT(x=10, y=20, z=30)
498496
for module in (pickle,):

Lib/test/test_configparser.py

+2
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,8 @@ def test_inconsistent_converters_state(self):
17021702
class ExceptionPicklingTestCase(unittest.TestCase):
17031703
"""Tests for issue #13760: ConfigParser exceptions are not picklable."""
17041704

1705+
# TODO: RUSTPYTHON Exception.__reduce__ missing.
1706+
@unittest.expectedFailure
17051707
def test_error(self):
17061708
import pickle
17071709
e1 = configparser.Error('value')

Lib/test/test_enum.py

-2
Original file line numberDiff line numberDiff line change
@@ -1191,8 +1191,6 @@ class TestAutoInt(AutoIntEnum):
11911191
b = 3
11921192
c = ...
11931193

1194-
# TODO: RUSTPYTHON
1195-
@unittest.expectedFailure
11961194
def test_subclasses_with_getnewargs(self):
11971195
class NamedInt(int):
11981196
__qualname__ = 'NamedInt' # needed for pickle protocol 4

Lib/unittest/test/test_discovery.py

+2
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ def test_discover_with_modules_that_fail_to_import(self):
498498
with self.assertRaises(ImportError):
499499
test.test_this_does_not_exist()
500500

501+
# TODO: RUSTPYTHON ImportError.__reduce__ missing
502+
@unittest.expectedFailure
501503
def test_discover_with_init_modules_that_fail_to_import(self):
502504
vfs = {abspath('/foo'): ['my_package'],
503505
abspath('/foo/my_package'): ['__init__.py', 'test_module.py']}

vm/src/builtins/pytype.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,9 @@ impl PyType {
467467
}
468468
}
469469

470+
// All *classes* should have a dict. Exceptions are *instances* of
471+
// classes that define __slots__ and instances of built-in classes
472+
// (with exceptions, e.g function)
470473
if !attributes.contains_key("__dict__") {
471474
attributes.insert(
472475
"__dict__".to_owned(),
@@ -479,9 +482,10 @@ impl PyType {
479482
);
480483
}
481484

482-
// TODO: how do we know if it should have a dict?
483-
let flags = base.slots.flags | PyTpFlags::HAS_DICT;
484-
485+
// TODO: Flags is currently initialized with HAS_DICT. Should be
486+
// updated when __slots__ are supported (toggling the flag off if
487+
// a class has __slots__ defined).
488+
let flags = PyTpFlags::heap_type_flags() | PyTpFlags::HAS_DICT;
485489
let slots = PyTypeSlots::from_flags(flags);
486490

487491
let typ = new(metatype, name.as_str(), base, bases, attributes, slots)

vm/src/slots.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@ bitflags! {
2525
}
2626

2727
impl PyTpFlags {
28+
// Default used for both built-in and normal classes: empty, for now.
2829
// CPython default: Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | Py_TPFLAGS_HAVE_VERSION_TAG
29-
pub const DEFAULT: Self = Self::HEAPTYPE;
30+
pub const DEFAULT: Self = Self::empty();
31+
32+
// CPython: See initialization of flags in type_new.
33+
/// Used for types created in Python. Subclassable and are a
34+
/// heaptype.
35+
pub fn heap_type_flags() -> Self {
36+
Self::DEFAULT | Self::HEAPTYPE | Self::BASETYPE
37+
}
3038

3139
pub fn has_feature(self, flag: Self) -> bool {
3240
self.contains(flag)

0 commit comments

Comments
 (0)