From 836dcc5ba06cde8eba64d35b2641a32b6b1508cc Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 23 Jul 2020 22:40:02 +1000 Subject: [PATCH] Document missing attributes --- docs/conf.py | 7 +------ docs/handbook/image-file-formats.rst | 14 +++++++------- src/PIL/ImageFile.py | 2 ++ src/PIL/TiffImagePlugin.py | 16 +++++++++++++--- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 5b42bba11..caddae327 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -114,12 +114,7 @@ nitpicky = True # generating warnings in “nitpicky mode”. Note that type should include the domain name # if present. Example entries would be ('py:func', 'int') or # ('envvar', 'LD_LIBRARY_PATH'). -nitpick_ignore = [ - ("py:attr", "PIL.Image.Image.tag"), - ("py:attr", "PIL.Image.Image.tag_v2"), - ("py:attr", "PIL.Image.Image.tile"), - ("py:attr", "PIL.TiffImagePlugin.ImageFileDirectory_v2.tagtype"), -] +# nitpick_ignore = [] # -- Options for HTML output ---------------------------------------------- diff --git a/docs/handbook/image-file-formats.rst b/docs/handbook/image-file-formats.rst index bd565f79c..89e3dfd4a 100644 --- a/docs/handbook/image-file-formats.rst +++ b/docs/handbook/image-file-formats.rst @@ -186,7 +186,7 @@ Reading local images The GIF loader creates an image memory the same size as the GIF file’s *logical screen size*, and pastes the actual pixel data (the *local image*) into this image. If you only want the actual pixel rectangle, you can manipulate the -:py:attr:`~PIL.Image.Image.size` and :py:attr:`~PIL.Image.Image.tile` +:py:attr:`~PIL.Image.Image.size` and :py:attr:`~PIL.ImageFile.ImageFile.tile` attributes before loading the file:: im = Image.open(...) @@ -764,8 +764,8 @@ The :py:meth:`~PIL.Image.open` method sets the following **dpi** Image resolution as an ``(xdpi, ydpi)`` tuple, where applicable. You can use - the :py:attr:`~PIL.Image.Image.tag` attribute to get more detailed - information about the image resolution. + the :py:attr:`~PIL.TiffImagePlugin.TiffImageFile.tag` attribute to get more + detailed information about the image resolution. .. versionadded:: 1.1.5 @@ -776,8 +776,8 @@ The :py:meth:`~PIL.Image.open` method sets the following .. versionadded:: 1.1.5 -The :py:attr:`~PIL.Image.Image.tag_v2` attribute contains a dictionary -of TIFF metadata. The keys are numerical indexes from +The :py:attr:`~PIL.TiffImagePlugin.TiffImageFile.tag_v2` attribute contains a +dictionary of TIFF metadata. The keys are numerical indexes from :py:data:`.TiffTags.TAGS_V2`. Values are strings or numbers for single items, multiple values are returned in a tuple of values. Rational numbers are returned as a :py:class:`~PIL.TiffImagePlugin.IFDRational` @@ -786,8 +786,8 @@ object. .. versionadded:: 3.0.0 For compatibility with legacy code, the -:py:attr:`~PIL.Image.Image.tag` attribute contains a dictionary of -decoded TIFF fields as returned prior to version 3.0.0. Values are +:py:attr:`~PIL.TiffImagePlugin.TiffImageFile.tag` attribute contains a dictionary +of decoded TIFF fields as returned prior to version 3.0.0. Values are returned as either strings or tuples of numeric values. Rational numbers are returned as a tuple of ``(numerator, denominator)``. diff --git a/src/PIL/ImageFile.py b/src/PIL/ImageFile.py index fd2e1bbde..648101ee3 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -95,6 +95,8 @@ class ImageFile(Image.Image): self.custom_mimetype = None self.tile = None + """ A list of tile descriptors, or ``None`` """ + self.readonly = 1 # until we know better self.decoderconfig = () diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index b56072737..012d25302 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -472,6 +472,8 @@ class ImageFileDirectory_v2(MutableMapping): self._endian = "<" else: raise SyntaxError("not a TIFF IFD") + self.tagtype = {} + """ Dictionary of tag types """ self.reset() (self.next,) = self._unpack("L", ifh[4:]) self._legacy_api = False @@ -972,17 +974,25 @@ class TiffImageFile(ImageFile.ImageFile): format_description = "Adobe TIFF" _close_exclusive_fp_after_loading = False + def __init__(self, fp=None, filename=None): + self.tag_v2 = None + """ Image file directory (tag dictionary) """ + + self.tag = None + """ Legacy tag entries """ + + super().__init__(fp, filename) + def _open(self): """Open the first image in a TIFF file""" # Header ifh = self.fp.read(8) - # image file directory (tag dictionary) self.tag_v2 = ImageFileDirectory_v2(ifh) - # legacy tag/ifd entries will be filled in later - self.tag = self.ifd = None + # legacy ifd entries will be filled in later + self.ifd = None # setup frame pointers self.__first = self.__next = self.tag_v2.next