MCPcopy Index your code
hub / github.com/python-openxml/python-docx / _get_by_id

Method _get_by_id

src/docx/styles/styles.py:107–116  ·  view source on GitHub ↗

Return the style of `style_type` matching `style_id`. Returns the default for `style_type` if `style_id` is not found or if the style having `style_id` is not of `style_type`.

(self, style_id: str | None, style_type: WD_STYLE_TYPE)

Source from the content-addressed store, hash-verified

105 return LatentStyles(self._element.get_or_add_latentStyles())
106
107 def _get_by_id(self, style_id: str | None, style_type: WD_STYLE_TYPE):
108 """Return the style of `style_type` matching `style_id`.
109
110 Returns the default for `style_type` if `style_id` is not found or if the style
111 having `style_id` is not of `style_type`.
112 """
113 style = self._element.get_by_id(style_id) if style_id else None
114 if style is None or style.type != style_type:
115 return self.default(style_type)
116 return StyleFactory(style)
117
118 def _get_style_id_from_name(self, style_name: str, style_type: WD_STYLE_TYPE) -> str | None:
119 """Return the id of the style of `style_type` corresponding to `style_name`.

Callers 2

get_by_idMethod · 0.95

Calls 3

defaultMethod · 0.95
StyleFactoryFunction · 0.90
get_by_idMethod · 0.45

Tested by 1