2
2
3
3
from __future__ import annotations
4
4
5
- from typing import TYPE_CHECKING
5
+ from typing import TYPE_CHECKING , Callable , Dict , Type
6
6
7
7
from docx .opc .oxml import serialize_part_xml
8
8
from docx .opc .packuri import PackURI
@@ -78,7 +78,7 @@ def drop_rel(self, rId: str):
78
78
del self .rels [rId ]
79
79
80
80
@classmethod
81
- def load (cls , partname , content_type , blob , package ):
81
+ def load (cls , partname : str , content_type : str , blob : bytes , package : Package ):
82
82
return cls (partname , content_type , blob , package )
83
83
84
84
def load_rel (self , reltype , target , rId , is_external = False ):
@@ -167,12 +167,19 @@ class PartFactory:
167
167
the part, which is by default ``opc.package.Part``.
168
168
"""
169
169
170
- part_class_selector = None
171
- part_type_for = {}
170
+ part_class_selector : Callable [[ str , str ], Type [ Part ] | None ] | None
171
+ part_type_for : Dict [ str , Type [ Part ]] = {}
172
172
default_part_type = Part
173
173
174
- def __new__ (cls , partname , content_type , reltype , blob , package ):
175
- PartClass = None
174
+ def __new__ (
175
+ cls ,
176
+ partname : str ,
177
+ content_type : str ,
178
+ reltype : str ,
179
+ blob : bytes ,
180
+ package : Package ,
181
+ ):
182
+ PartClass : Type [Part ] | None = None
176
183
if cls .part_class_selector is not None :
177
184
part_class_selector = cls_method_fn (cls , "part_class_selector" )
178
185
PartClass = part_class_selector (content_type , reltype )
@@ -181,7 +188,7 @@ def __new__(cls, partname, content_type, reltype, blob, package):
181
188
return PartClass .load (partname , content_type , blob , package )
182
189
183
190
@classmethod
184
- def _part_cls_for (cls , content_type ):
191
+ def _part_cls_for (cls , content_type : str ):
185
192
"""Return the custom part class registered for `content_type`, or the default
186
193
part class if no custom class is registered for `content_type`."""
187
194
if content_type in cls .part_type_for :
0 commit comments