mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Improved typing for ImageDraw
This commit is contained in:
		
							parent
							
								
									569b785371
								
							
						
					
					
						commit
						69ae6662cb
					
				| 
						 | 
					@ -39,7 +39,7 @@ from typing import TYPE_CHECKING, Any, AnyStr, Callable, Union, cast
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from . import Image, ImageColor
 | 
					from . import Image, ImageColor
 | 
				
			||||||
from ._deprecate import deprecate
 | 
					from ._deprecate import deprecate
 | 
				
			||||||
from ._typing import Coords
 | 
					from ._typing import Coords, Anchor, Align, Direction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# experimental access to the outline API
 | 
					# experimental access to the outline API
 | 
				
			||||||
Outline: Callable[[], Image.core._Outline] | None
 | 
					Outline: Callable[[], Image.core._Outline] | None
 | 
				
			||||||
| 
						 | 
					@ -241,7 +241,7 @@ class ImageDraw:
 | 
				
			||||||
        xy: Coords,
 | 
					        xy: Coords,
 | 
				
			||||||
        fill: _Ink | None = None,
 | 
					        fill: _Ink | None = None,
 | 
				
			||||||
        width: int = 0,
 | 
					        width: int = 0,
 | 
				
			||||||
        joint: str | None = None,
 | 
					        joint: Literal["curve"] | None = None,
 | 
				
			||||||
    ) -> None:
 | 
					    ) -> None:
 | 
				
			||||||
        """Draw a line, or a connected sequence of line segments."""
 | 
					        """Draw a line, or a connected sequence of line segments."""
 | 
				
			||||||
        ink = self._getink(fill)[0]
 | 
					        ink = self._getink(fill)[0]
 | 
				
			||||||
| 
						 | 
					@ -583,10 +583,10 @@ class ImageDraw:
 | 
				
			||||||
            | ImageFont.TransposedFont
 | 
					            | ImageFont.TransposedFont
 | 
				
			||||||
            | None
 | 
					            | None
 | 
				
			||||||
        ) = None,
 | 
					        ) = None,
 | 
				
			||||||
        anchor: str | None = None,
 | 
					        anchor: Anchor | None = None,
 | 
				
			||||||
        spacing: float = 4,
 | 
					        spacing: float = 4,
 | 
				
			||||||
        align: str = "left",
 | 
					        align: Align = "left",
 | 
				
			||||||
        direction: str | None = None,
 | 
					        direction: Direction | None = None,
 | 
				
			||||||
        features: list[str] | None = None,
 | 
					        features: list[str] | None = None,
 | 
				
			||||||
        language: str | None = None,
 | 
					        language: str | None = None,
 | 
				
			||||||
        stroke_width: float = 0,
 | 
					        stroke_width: float = 0,
 | 
				
			||||||
| 
						 | 
					@ -708,10 +708,10 @@ class ImageDraw:
 | 
				
			||||||
            | ImageFont.TransposedFont
 | 
					            | ImageFont.TransposedFont
 | 
				
			||||||
            | None
 | 
					            | None
 | 
				
			||||||
        ) = None,
 | 
					        ) = None,
 | 
				
			||||||
        anchor: str | None = None,
 | 
					        anchor: Anchor | None = None,
 | 
				
			||||||
        spacing: float = 4,
 | 
					        spacing: float = 4,
 | 
				
			||||||
        align: str = "left",
 | 
					        align: Align = "left",
 | 
				
			||||||
        direction: str | None = None,
 | 
					        direction: Direction | None = None,
 | 
				
			||||||
        features: list[str] | None = None,
 | 
					        features: list[str] | None = None,
 | 
				
			||||||
        language: str | None = None,
 | 
					        language: str | None = None,
 | 
				
			||||||
        stroke_width: float = 0,
 | 
					        stroke_width: float = 0,
 | 
				
			||||||
| 
						 | 
					@ -798,7 +798,7 @@ class ImageDraw:
 | 
				
			||||||
            | ImageFont.TransposedFont
 | 
					            | ImageFont.TransposedFont
 | 
				
			||||||
            | None
 | 
					            | None
 | 
				
			||||||
        ) = None,
 | 
					        ) = None,
 | 
				
			||||||
        direction: str | None = None,
 | 
					        direction: Direction | None = None,
 | 
				
			||||||
        features: list[str] | None = None,
 | 
					        features: list[str] | None = None,
 | 
				
			||||||
        language: str | None = None,
 | 
					        language: str | None = None,
 | 
				
			||||||
        embedded_color: bool = False,
 | 
					        embedded_color: bool = False,
 | 
				
			||||||
| 
						 | 
					@ -828,10 +828,10 @@ class ImageDraw:
 | 
				
			||||||
            | ImageFont.TransposedFont
 | 
					            | ImageFont.TransposedFont
 | 
				
			||||||
            | None
 | 
					            | None
 | 
				
			||||||
        ) = None,
 | 
					        ) = None,
 | 
				
			||||||
        anchor: str | None = None,
 | 
					        anchor: Anchor | None = None,
 | 
				
			||||||
        spacing: float = 4,
 | 
					        spacing: float = 4,
 | 
				
			||||||
        align: str = "left",
 | 
					        align: Align = "left",
 | 
				
			||||||
        direction: str | None = None,
 | 
					        direction: Direction | None = None,
 | 
				
			||||||
        features: list[str] | None = None,
 | 
					        features: list[str] | None = None,
 | 
				
			||||||
        language: str | None = None,
 | 
					        language: str | None = None,
 | 
				
			||||||
        stroke_width: float = 0,
 | 
					        stroke_width: float = 0,
 | 
				
			||||||
| 
						 | 
					@ -878,10 +878,10 @@ class ImageDraw:
 | 
				
			||||||
            | ImageFont.TransposedFont
 | 
					            | ImageFont.TransposedFont
 | 
				
			||||||
            | None
 | 
					            | None
 | 
				
			||||||
        ) = None,
 | 
					        ) = None,
 | 
				
			||||||
        anchor: str | None = None,
 | 
					        anchor: Anchor | None = None,
 | 
				
			||||||
        spacing: float = 4,
 | 
					        spacing: float = 4,
 | 
				
			||||||
        align: str = "left",
 | 
					        align: Align = "left",
 | 
				
			||||||
        direction: str | None = None,
 | 
					        direction: Direction | None = None,
 | 
				
			||||||
        features: list[str] | None = None,
 | 
					        features: list[str] | None = None,
 | 
				
			||||||
        language: str | None = None,
 | 
					        language: str | None = None,
 | 
				
			||||||
        stroke_width: float = 0,
 | 
					        stroke_width: float = 0,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,7 @@ from __future__ import annotations
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
from collections.abc import Sequence
 | 
					from collections.abc import Sequence
 | 
				
			||||||
from typing import TYPE_CHECKING, Any, Protocol, TypeVar, Union
 | 
					from typing import TYPE_CHECKING, Any, Protocol, TypeVar, Union, Literal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if TYPE_CHECKING:
 | 
					if TYPE_CHECKING:
 | 
				
			||||||
    from numbers import _IntegralLike as IntegralLike
 | 
					    from numbers import _IntegralLike as IntegralLike
 | 
				
			||||||
| 
						 | 
					@ -49,5 +49,12 @@ class SupportsRead(Protocol[_T_co]):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
StrOrBytesPath = Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]
 | 
					StrOrBytesPath = Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					horizontal_anchors = ("l", "m", "r", "s")
 | 
				
			||||||
 | 
					vertical_anchors = ("a", "t", "m", "s", "b", "d")
 | 
				
			||||||
 | 
					Anchor = Literal[*(horizontal_anchor + vertical_anchor for horizontal_anchor in horizontal_anchors for vertical_anchor in vertical_anchors)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Align = Literal["left", "center", "right"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Direction = Literal["rtl", "ltr", "ttb"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
__all__ = ["Buffer", "IntegralLike", "StrOrBytesPath", "SupportsRead", "TypeGuard"]
 | 
					__all__ = ["Buffer", "IntegralLike", "StrOrBytesPath", "SupportsRead", "TypeGuard"]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user