@@ -64,10 +64,10 @@ class Node:
64
64
def __init__ (self ,
65
65
node_type : NodeType ,
66
66
node_name : DOMString ,
67
+ owner_document : Optional [_Document ],
67
68
node_value : Optional [DOMString ] = None ,
68
69
child_nodes : Optional [Iterable [_AnyNode ]] = None ,
69
70
attributes : Optional [Iterable [_AnyNode ]] = None ,
70
- owner_document : Optional [_Document ] = None ,
71
71
read_only : bool = False ) -> None :
72
72
if node_value is None :
73
73
node_value = ''
@@ -87,7 +87,7 @@ def __init__(self,
87
87
self ._parent_node : Optional [_AnyNode ]
88
88
self ._child_nodes : NodeList
89
89
self ._attributes : _NamedNodeMap
90
- self ._owner_document : _Document
90
+ self ._owner_document : Optional [ _Document ]
91
91
self ._read_only : bool
92
92
93
93
def _check_modifiable (self ) -> None :
@@ -256,13 +256,16 @@ def owner_document(self) -> Optional[_Document]:
256
256
This is also the `Document` object used to create new nodes.
257
257
When this node is a `Document` this is `None`.
258
258
"""
259
- if self .node_type == NodeType .DOCUMENT_NODE :
260
- return None
261
259
return self ._owner_document
262
260
263
261
def _set_owner_document (self ,
264
262
owner_document : Optional [_Document ] = None ) -> None :
265
263
"""Indirect accessor to set the 'owner_document' property."""
264
+ if owner_document is None :
265
+ if self .node_type != NodeType .DOCUMENT_NODE :
266
+ raise ValueError ('`Node` should have a `Document` object ' ,
267
+ 'which associated with this node, ' ,
268
+ 'Unless this node is a `Document`.' )
266
269
self ._owner_document = owner_document
267
270
268
271
def insert_before (self ,
0 commit comments