|
4 | 4 |
|
5 | 5 | @author: Eric Lapouyade |
6 | 6 | """ |
| 7 | + |
| 8 | +from __future__ import annotations |
| 9 | + |
| 10 | +from typing import IO, TYPE_CHECKING |
| 11 | + |
7 | 12 | from docx.oxml import OxmlElement, parse_xml |
8 | 13 | from docx.oxml.ns import qn |
9 | 14 |
|
| 15 | +if TYPE_CHECKING: |
| 16 | + from docx.shared import Length |
| 17 | + from .template import DocxTemplate |
| 18 | + |
10 | 19 |
|
11 | 20 | class InlineImage(object): |
12 | 21 | """Class to generate an inline image |
13 | 22 |
|
14 | 23 | This is much faster than using Subdoc class. |
15 | 24 | """ |
16 | 25 |
|
17 | | - tpl = None |
18 | | - image_descriptor = None |
19 | | - width = None |
20 | | - height = None |
| 26 | + tpl: DocxTemplate = None # type:ignore[assignment] |
| 27 | + image_descriptor: str | IO[bytes] = None # type:ignore[assignment] |
| 28 | + width: int | Length | None = None |
| 29 | + height: int | Length | None = None |
21 | 30 | anchor = None |
22 | 31 |
|
23 | | - def __init__(self, tpl, image_descriptor, width=None, height=None, anchor=None): |
| 32 | + def __init__( |
| 33 | + self, |
| 34 | + tpl: DocxTemplate, |
| 35 | + image_descriptor: str | IO[bytes], |
| 36 | + width: int | Length | None = None, |
| 37 | + height: int | Length | None = None, |
| 38 | + anchor=None, |
| 39 | + ) -> None: |
24 | 40 | self.tpl, self.image_descriptor = tpl, image_descriptor |
25 | 41 | self.width, self.height = width, height |
26 | 42 | self.anchor = anchor |
@@ -49,8 +65,8 @@ def _add_hyperlink(self, run, url, part): |
49 | 65 |
|
50 | 66 | return run |
51 | 67 |
|
52 | | - def _insert_image(self): |
53 | | - pic = self.tpl.current_rendering_part.new_pic_inline( |
| 68 | + def _insert_image(self) -> str: |
| 69 | + pic = self.tpl.current_rendering_part.new_pic_inline( # type:ignore |
54 | 70 | self.image_descriptor, |
55 | 71 | self.width, |
56 | 72 | self.height, |
|
0 commit comments