|
3 | 3 | import typing as tp |
4 | 4 |
|
5 | 5 | from PIL import Image |
6 | | -from multimethod import multidispatch |
7 | 6 |
|
8 | 7 | from applitools.core import RegionProvider |
9 | 8 | from applitools.core.utils import image_utils |
@@ -126,28 +125,14 @@ def timeout(self, timeout): |
126 | 125 |
|
127 | 126 | def image(self, image_or_path): |
128 | 127 | # type: (tp.Union[Image.Image, tp.Text]) -> Target |
129 | | - self._image = _image_dispatch(image_or_path) |
| 128 | + if isinstance(image_or_path, Image.Image): |
| 129 | + self._image = image_or_path |
| 130 | + elif isinstance(image_or_path, str) or isinstance(image_or_path, tp.Text): |
| 131 | + self._image = image_utils.image_from_file(image_or_path) |
130 | 132 | return self |
131 | 133 |
|
132 | 134 | def region(self, image_or_path, rect): |
133 | 135 | # type: (tp.Union[Image.Image, tp.Text], Region) -> Target |
134 | 136 | target = self.image(image_or_path) |
135 | 137 | target._target_region = rect |
136 | 138 | return target |
137 | | - |
138 | | - |
139 | | -@multidispatch |
140 | | -def _image_dispatch(image): |
141 | | - raise TypeError('Not supported type.') |
142 | | - |
143 | | - |
144 | | -@_image_dispatch.register(Image.Image) # type: ignore |
145 | | -def __image_dispatch(image): |
146 | | - return image |
147 | | - |
148 | | - |
149 | | -@_image_dispatch.register(tp.Text) # type: ignore |
150 | | -@_image_dispatch.register(str) |
151 | | -def __image_dispatch(image_path): |
152 | | - image = image_utils.image_from_file(image_path) |
153 | | - return image |
0 commit comments