mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-27 15:44:46 +03:00
Type annotations: Image.py: Improve many annotations.
This commit is contained in:
parent
0303544f1a
commit
67d353c15f
34
PIL/Image.py
34
PIL/Image.py
|
@ -285,7 +285,7 @@ _MODE_CONV = {
|
|||
|
||||
|
||||
def _conv_type_shape(im):
|
||||
# type: (Image) -> Tuple
|
||||
# type: (Image) -> Tuple[Size, Tuple[Text, Optional[int]]] # NOTE: Size inverted compared to normal
|
||||
typ, extra = _MODE_CONV[im.mode]
|
||||
if extra is None:
|
||||
return (im.size[1], im.size[0]), typ
|
||||
|
@ -328,7 +328,7 @@ def getmodetype(mode):
|
|||
|
||||
|
||||
def getmodebandnames(mode):
|
||||
# type: (Mode) -> Tuple
|
||||
# type: (Mode) -> Tuple[Any, ...] ## FIXME TYPING: Any is 'Band' or Mode?
|
||||
"""
|
||||
Gets a list of individual band names. Given a mode, this function returns
|
||||
a tuple containing the names of individual bands (use
|
||||
|
@ -704,7 +704,7 @@ class Image(object):
|
|||
self.tobytes()]
|
||||
|
||||
def __setstate__(self, state):
|
||||
# type: (Tuple) -> None
|
||||
# type: (Tuple[Any, Mode, Size, Any, Any]) -> None ## FIXME TYPING: Define types better
|
||||
Image.__init__(self)
|
||||
self.tile = [] # type: List[Tuple] ## FIXME Should tile be in __init__ & _new?
|
||||
# FIXME TYPING: ^ Maybe Optional[List[Tuple[Text, LURD, int, Optional[Tuple]]]] ?
|
||||
|
@ -789,7 +789,7 @@ class Image(object):
|
|||
])
|
||||
|
||||
def frombytes(self, data, decoder_name="raw", *args):
|
||||
# type: (Any, Text, *Any) -> None ### FIXME TYPING: What type is data? bytearray?
|
||||
# type: (bytes, Text, *Any) -> None
|
||||
"""
|
||||
Loads this image with pixel data from a bytes object.
|
||||
|
||||
|
@ -1137,9 +1137,8 @@ class Image(object):
|
|||
return im.crop((x0, y0, x1, y1))
|
||||
|
||||
def draft(self, mode, size):
|
||||
# type: (Mode, Size) -> Any
|
||||
# FIXME TYPING: return type clarification
|
||||
# FIXME TYPING: thumbnail calls as (None, size), so is it Optional[Mode]?
|
||||
# type: (Optional[Mode], Size) -> Any
|
||||
# FIXME TYPING: return type clarification (returns self, like JPEG? inconsistent?)
|
||||
"""
|
||||
Configures the image file loader so it returns a version of the
|
||||
image that as closely as possible matches the given mode and
|
||||
|
@ -1218,7 +1217,7 @@ class Image(object):
|
|||
return self.im.getbbox()
|
||||
|
||||
def getcolors(self, maxcolors=256):
|
||||
# type: (int) -> Optional[List[Tuple[int, int]]] ### FIXME TYPING Should be Tuple[int, 'Color'] ?
|
||||
# type: (int) -> Optional[List[Tuple[int, Color]]] ### FIXME TYPING: Check this
|
||||
"""
|
||||
Returns a list of colors used in this image.
|
||||
|
||||
|
@ -1313,7 +1312,7 @@ class Image(object):
|
|||
return None # no palette
|
||||
|
||||
def getpixel(self, xy):
|
||||
# type: (Coord) -> Tuple[Any] ## FIXME TYPING: Once Color[spec] is aliases, this can be done?
|
||||
# type: (Coord) -> Optional[Color] ## FIXME TYPING: Check this
|
||||
"""
|
||||
Returns the pixel value at a given position.
|
||||
|
||||
|
@ -1376,7 +1375,8 @@ class Image(object):
|
|||
"Please call ImageChops.offset() instead.")
|
||||
|
||||
def paste(self, im, box=None, mask=None):
|
||||
# type: (Union[Image, int, Tuple, Text], Optional[Union[LURD, Coord]], Optional[Image]) -> None
|
||||
# type: (Union[Image, Color, Text], Optional[Union[LURD, Coord]], Optional[Image]) -> None
|
||||
## FIXME TYPING: Check this ^
|
||||
"""
|
||||
Pastes another image into this image. The box argument is either
|
||||
a 2-tuple giving the upper left corner, a 4-tuple defining the
|
||||
|
@ -1549,7 +1549,7 @@ class Image(object):
|
|||
return self._new(self.im.point(lut, mode))
|
||||
|
||||
def putalpha(self, alpha):
|
||||
# type: (Union[Image, int, Tuple]) -> None
|
||||
# type: (Union[Image, Color]) -> None ## FIXME TYPING: Check this
|
||||
"""
|
||||
Adds or replaces the alpha layer in this image. If the image
|
||||
does not have an alpha layer, it's converted to "LA" or "RGBA".
|
||||
|
@ -1607,7 +1607,7 @@ class Image(object):
|
|||
self.im.putband(alpha.im, band)
|
||||
|
||||
def putdata(self, data, scale=1.0, offset=0.0):
|
||||
# type: (Sequence[Any], float, float) -> None ## FIXME TYPING: Sequence[bytes] ?
|
||||
# type: (Sequence[Union[bytes, int, float]], float, float) -> None
|
||||
"""
|
||||
Copies pixel data to this image. This method copies data from a
|
||||
sequence object into the image, starting at the upper left
|
||||
|
@ -1658,8 +1658,8 @@ class Image(object):
|
|||
self.load() # install new palette
|
||||
|
||||
def putpixel(self, xy, value):
|
||||
# type: (Coord, Union[int, Tuple]) -> Any
|
||||
## FIXME TYPING: ImagingCore.putpixel returns None, so this can too?
|
||||
# type: (Coord, Union[int, Tuple]) -> None ## FIXME TYPING: value is 'Color', rather than Union?
|
||||
## FIXME: ImagingCore.putpixel returns None, so this can too?
|
||||
"""
|
||||
Modifies the pixel at the given position. The color is given as
|
||||
a single numerical value for single-band images, and a tuple for
|
||||
|
@ -2157,7 +2157,7 @@ class Image(object):
|
|||
# FIXME: the different transform methods need further explanation
|
||||
# instead of bloating the method docs, add a separate chapter.
|
||||
def transform(self, size, method, data=None, resample=NEAREST, fill=1):
|
||||
# type: (Size, int, Optional[Any], int, Any) -> Image ## FIXME TYPING: What are Any here?
|
||||
# type: (Size, int, Optional[List[float]], int, int) -> Image
|
||||
"""
|
||||
Transforms this image. This method creates a new image with the
|
||||
given size, and the same mode as the original, and copies data
|
||||
|
@ -2347,7 +2347,7 @@ def _check_size(size):
|
|||
|
||||
|
||||
def new(mode, size, color=0):
|
||||
# type: (Mode, Size, Optional[Union[int, float, Tuple, Text]]) -> Image
|
||||
# type: (Mode, Size, Optional[Union[Color, Text]]) -> Image ## FIXME TYPING: Check this
|
||||
"""
|
||||
Creates a new image with the given mode and size.
|
||||
|
||||
|
@ -2645,7 +2645,7 @@ def open(fp, mode="r"):
|
|||
preinit()
|
||||
|
||||
def _open_core(fp, filename, prefix):
|
||||
# # type: (Any, Text, Text): -> Optional[Image] # FIXME TYPING: Is Any BinaryIO here?
|
||||
# type: (BinaryIO, Text, Text) -> Optional[Image]
|
||||
for i in ID:
|
||||
try:
|
||||
factory, accept = OPEN[i]
|
||||
|
|
Loading…
Reference in New Issue
Block a user