22
33from __future__ import annotations
44
5- from typing import TYPE_CHECKING
5+ from typing import TYPE_CHECKING , Callable , Dict , Type
66
77from docx .opc .oxml import serialize_part_xml
88from docx .opc .packuri import PackURI
@@ -78,7 +78,7 @@ def drop_rel(self, rId: str):
7878 del self .rels [rId ]
7979
8080 @classmethod
81- def load (cls , partname , content_type , blob , package ):
81+ def load (cls , partname : str , content_type : str , blob : bytes , package : Package ):
8282 return cls (partname , content_type , blob , package )
8383
8484 def load_rel (self , reltype , target , rId , is_external = False ):
@@ -167,12 +167,19 @@ class PartFactory:
167167 the part, which is by default ``opc.package.Part``.
168168 """
169169
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 ]] = {}
172172 default_part_type = Part
173173
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
176183 if cls .part_class_selector is not None :
177184 part_class_selector = cls_method_fn (cls , "part_class_selector" )
178185 PartClass = part_class_selector (content_type , reltype )
@@ -181,7 +188,7 @@ def __new__(cls, partname, content_type, reltype, blob, package):
181188 return PartClass .load (partname , content_type , blob , package )
182189
183190 @classmethod
184- def _part_cls_for (cls , content_type ):
191+ def _part_cls_for (cls , content_type : str ):
185192 """Return the custom part class registered for `content_type`, or the default
186193 part class if no custom class is registered for `content_type`."""
187194 if content_type in cls .part_type_for :
0 commit comments