Type annotations: Label all obvious issues and label with 'FIXME TYPING'.

This commit is contained in:
neiljp (Neil Pilgrim) 2017-08-20 19:43:00 -07:00 committed by Eric Soroos
parent ab40a28c1c
commit 1af865813d

View File

@ -31,11 +31,11 @@ if False:
# Just required for typing, or gradual module inclusion while adding annotation? # Just required for typing, or gradual module inclusion while adding annotation?
import pathlib import pathlib
# from . import ImagingPalette ## This will need a stub? # from . import ImagingPalette ## FIXME TYPING This will need a stub?
from . import ImagePalette from . import ImagePalette
from .ImageFilter import Filter from .ImageFilter import Filter
from .ImageFile import PyDecoder from .ImageFile import PyDecoder
PyEncoder = Any ## FIXME: PyEncoder is not defined anywhere? Needs stub/class? PyEncoder = Any ## FIXME TYPING: PyEncoder is not defined anywhere? Needs stub/class?
from ._imaging import ImagingCore from ._imaging import ImagingCore
from . import VERSION, PILLOW_VERSION, _plugins from . import VERSION, PILLOW_VERSION, _plugins
@ -433,7 +433,7 @@ def init():
_initialized = 2 _initialized = 2
return 1 return 1
# FIXME: mypy suggests a default return may be necessary here? # FIXME TYPING: mypy suggests a default return may be necessary here?
# -------------------------------------------------------------------- # --------------------------------------------------------------------
@ -726,7 +726,8 @@ class Image(object):
def __setstate__(self, state): def __setstate__(self, state):
# type: (Tuple) -> None # type: (Tuple) -> None
Image.__init__(self) Image.__init__(self)
self.tile = [] # type: List[Tuple] ## FIXME More detail? Should tile be in __init__ & _new? self.tile = [] # type: List[Tuple] ## FIXME Should tile be in __init__ & _new?
# FIXME TYPING: ^ Maybe Optional[List[Tuple[Text, LURD, int, Optional[Tuple]]]] ?
info, mode, size, palette, data = state info, mode, size, palette, data = state
self.info = info self.info = info
self.mode = mode self.mode = mode
@ -808,7 +809,7 @@ class Image(object):
]) ])
def frombytes(self, data, decoder_name="raw", *args): def frombytes(self, data, decoder_name="raw", *args):
# type: (Any, Text, *Any) -> None # type: (Any, Text, *Any) -> None ### FIXME TYPING: What type is data? bytearray?
""" """
Loads this image with pixel data from a bytes object. Loads this image with pixel data from a bytes object.
@ -1155,7 +1156,8 @@ class Image(object):
def draft(self, mode, size): def draft(self, mode, size):
# type: (Mode, Size) -> Any # type: (Mode, Size) -> Any
# TODO: return type clarification # FIXME TYPING: return type clarification
# FIXME TYPING: thumbnail calls as (None, size), so is it Optional[Mode]?
""" """
Configures the image file loader so it returns a version of the Configures the image file loader so it returns a version of the
image that as closely as possible matches the given mode and image that as closely as possible matches the given mode and
@ -1211,7 +1213,7 @@ class Image(object):
return merge(self.mode, ims) return merge(self.mode, ims)
def getbands(self): def getbands(self):
# type: () -> Tuple[Any] # type: () -> Tuple[Any] ## FIXME TYPING: Define a type alias, or just use Mode?
""" """
Returns a tuple containing the name of each band in this image. Returns a tuple containing the name of each band in this image.
For example, **getbands** on an RGB image returns ("R", "G", "B"). For example, **getbands** on an RGB image returns ("R", "G", "B").
@ -1237,7 +1239,7 @@ class Image(object):
return self.im.getbbox() return self.im.getbbox()
def getcolors(self, maxcolors=256): def getcolors(self, maxcolors=256):
# type: (int) -> Optional[List[Tuple[int, int]]] # type: (int) -> Optional[List[Tuple[int, int]]] ### FIXME TYPING Should be Tuple[int, 'Color'] ?
""" """
Returns a list of colors used in this image. Returns a list of colors used in this image.
@ -1303,7 +1305,7 @@ class Image(object):
return self.im.getextrema() return self.im.getextrema()
def getim(self): def getim(self):
# type: () -> Any # type: () -> Any ## FIXME TYPING: Can this be improved upon? Ask python/typeshed?
""" """
Returns a capsule that points to the internal image memory. Returns a capsule that points to the internal image memory.
@ -1332,7 +1334,7 @@ class Image(object):
return None # no palette return None # no palette
def getpixel(self, xy): def getpixel(self, xy):
# type: (Coord) -> Tuple[Any] # type: (Coord) -> Tuple[Any] ## FIXME TYPING: Once Color[spec] is aliases, this can be done?
""" """
Returns the pixel value at a given position. Returns the pixel value at a given position.
@ -1621,7 +1623,7 @@ class Image(object):
self.im.putband(alpha.im, band) self.im.putband(alpha.im, band)
def putdata(self, data, scale=1.0, offset=0.0): def putdata(self, data, scale=1.0, offset=0.0):
# type: (Sequence[Any], float, float) -> None # type: (Sequence[Any], float, float) -> None ## FIXME TYPING: Sequence[bytes] ?
""" """
Copies pixel data to this image. This method copies data from a Copies pixel data to this image. This method copies data from a
sequence object into the image, starting at the upper left sequence object into the image, starting at the upper left
@ -1672,6 +1674,7 @@ class Image(object):
def putpixel(self, xy, value): def putpixel(self, xy, value):
# type: (Coord, Union[int, Tuple]) -> Any # type: (Coord, Union[int, Tuple]) -> Any
## FIXME TYPING: ImagingCore.putpixel returns None, so this can too?
""" """
Modifies the pixel at the given position. The color is given as Modifies the pixel at the given position. The color is given as
a single numerical value for single-band images, and a tuple for a single numerical value for single-band images, and a tuple for
@ -2224,7 +2227,7 @@ class Image(object):
def __transformer(self, box, image, method, data, def __transformer(self, box, image, method, data,
resample=NEAREST, fill=1): resample=NEAREST, fill=1):
# type: (LURD, Image, int, Any, int, Any) -> None # type: (LURD, Image, int, Any, int, Any) -> None # FIXME TYPING: What are Any here?
w = box[2] - box[0] w = box[2] - box[0]
h = box[3] - box[1] h = box[3] - box[1]
@ -2659,7 +2662,7 @@ def open(fp, mode="r"):
preinit() preinit()
def _open_core(fp, filename, prefix): def _open_core(fp, filename, prefix):
# # type: (Any, Text, Text): -> Optional[Image] # # type: (Any, Text, Text): -> Optional[Image] # FIXME TYPING: Is Any BinaryIO here?
for i in ID: for i in ID:
try: try:
factory, accept = OPEN[i] factory, accept = OPEN[i]