8000 GH-92123: Move _elementtree heap types to module state by erlend-aasland · Pull Request #101187 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-92123: Move _elementtree heap types to module state #101187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
76641a3
Prepare init function
Nov 20, 2020
5cbbe16
Convert element type to heap type
Nov 20, 2020
116fa39
Convert element iter type to heap type
Nov 20, 2020
a792fcf
Convert tree builder type to heap type
Nov 20, 2020
341a92d
Convert xml parser type to heap type
Nov 20, 2020
f35c604
Update clinic
Nov 20, 2020
b6573b1
Add NEWS
Nov 20, 2020
404b398
Use PyModule_AddObjectRef
Nov 20, 2020
6e53e92
Create module before creating types
Nov 20, 2020
525cfaf
Fetch type before GC
Nov 21, 2020
2448e93
Add initialisation guard
Nov 21, 2020
959a225
Address Heime's review: Don't define globals twice
Nov 23, 2020
9210a36
Visit type in type traverse functions
Jan 11, 2021
a6c6fea
Fix NEWS formatting
Jan 11, 2021
e039922
Sync with main
erlend-aasland Nov 7, 2022
b02b18e
Sync with main
erlend-aasland Jan 12, 2023
744be65
Merge branch 'main' into isolate-elementtree
erlend-aasland Jan 18, 2023
c8a3c67
Address review: make types immutable
erlend-aasland Jan 18, 2023
2175f66
Disallow instantiation for the iter type 8000
erlend-aasland Jan 19, 2023
1ef41e1
PEP 687: Move types to state struct
erlend-aasland Jan 18, 2023
dbc4417
Sync with main
erlend-aasland Jan 20, 2023
24794dd
refactor: replace query with parameter
erlend-aasland Jan 20, 2023
6bb6511
refactor: replace query with parameter
erlend-aasland Jan 20, 2023
8dccc5a
refactor: replace query with parameter
erlend-aasland Jan 20, 2023
d10ecd0
Readability improvement
erlend-aasland Jan 20, 2023
04807e0
Merge branch 'main' into etree/move-heap-types-to-state
kumaraditya303 Jan 21, 2023
78d1676
Update Modules/_elementtree.c
erlend-aasland Jan 21, 2023
40fb571
Address review: remove etree types from globals-to-fix.tsv
erlend-aasland Jan 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review: make types immutable
  • Loading branch information
erlend-aasland committed Jan 18, 2023
commit c8a3c67df3d42aa5d12cda7ee220f714ec246b43
14 changes: 14 additions & 0 deletions Lib/test/test_xml_etree_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ def __hash__(self):
r = e.get(X())
self.assertIsNone(r)

@support.cpython_only
def test_immutable_types(self):
root = cET.fromstring('<a></a>')
dataset = (
cET.Element,
cET.TreeBuilder,
cET.XMLParser,
type(root.iter()),
)
for tp in dataset:
with self.subTest(tp=tp):
with self.assertRaisesRegex(TypeError, "immutable"):
tp.foo = 1


@unittest.skipUnless(cET, 'requires _elementtree')
class TestAliasWorking(unittest.TestCase):
Expand Down
11 changes: 7 additions & 4 deletions Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,8 @@ static PyType_Spec elementiter_spec = {
have such a type. */
.name = "_elementtree._element_iterator",
.basicsize = sizeof(ElementIterObject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = elementiter_slots,
};

Expand Down Expand Up @@ -4120,7 +4121,8 @@ static PyType_Slot element_slots[] = {
static PyType_Spec element_spec = {
.name = "xml.etree.ElementTree.Element",
.basicsize = sizeof(ElementObject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = element_slots,
};

Expand Down Expand Up @@ -4148,7 +4150,7 @@ static PyType_Slot treebuilder_slots[] = {
static PyType_Spec treebuilder_spec = {
.name = "xml.etree.ElementTree.TreeBuilder",
.basicsize = sizeof(TreeBuilderObject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE,
.slots = treebuilder_slots,
};

Expand Down Expand Up @@ -4176,7 +4178,8 @@ static PyType_Slot xmlparser_slots[] = {
static PyType_Spec xmlparser_spec = {
.name = "xml.etree.ElementTree.XMLParser",
.basicsize = sizeof(XMLParserObject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = xmlparser_slots,
};

Expand Down
0