Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Python code-blocks with double colons #6958

Merged
merged 2 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions docs/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ Deprecated Use
:py:meth:`.ImageDraw2.Draw.textsize` :py:meth:`.ImageDraw2.Draw.textbbox` and :py:meth:`.ImageDraw2.Draw.textlength`
=========================================================================== =============================================================================================================

Previous code:

.. code-block:: python
Previous code::

from PIL import Image, ImageDraw, ImageFont

Expand All @@ -194,9 +192,7 @@ Previous code:
width, height = font.getsize_multiline("Hello\nworld")
width, height = draw.multiline_textsize("Hello\nworld")

Use instead:

.. code-block:: python
Use instead::

from PIL import Image, ImageDraw, ImageFont

Expand Down Expand Up @@ -336,16 +332,12 @@ Implicitly closing the image's underlying file in ``Image.__del__`` has been rem
Use a context manager or call ``Image.close()`` instead to close the file in a
deterministic way.

Previous method:

.. code-block:: python
Previous method::

im = Image.open("hopper.png")
im.save("out.jpg")

Use instead:

.. code-block:: python
Use instead::

with Image.open("hopper.png") as im:
im.save("out.jpg")
Expand Down
8 changes: 2 additions & 6 deletions docs/handbook/image-file-formats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1393,9 +1393,7 @@ WMF, EMF
Pillow can identify WMF and EMF files.

On Windows, it can read WMF and EMF files. By default, it will load the image
at 72 dpi. To load it at another resolution:

.. code-block:: python
at 72 dpi. To load it at another resolution::

from PIL import Image

Expand All @@ -1404,9 +1402,7 @@ at 72 dpi. To load it at another resolution:

To add other read or write support, use
:py:func:`PIL.WmfImagePlugin.register_handler` to register a WMF and EMF
handler.

.. code-block:: python
handler. ::

from PIL import Image
from PIL import WmfImagePlugin
Expand Down
2 changes: 1 addition & 1 deletion docs/handbook/text-anchors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example, in the following image, the text is ``ms`` (middle-baseline) aligne
:alt: ms (middle-baseline) aligned text.
:align: left

.. code-block:: python
::

from PIL import Image, ImageDraw, ImageFont

Expand Down
12 changes: 3 additions & 9 deletions docs/handbook/writing-your-own-image-plugin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ Note that the image plugin must be explicitly registered using
:py:func:`PIL.Image.register_open`. Although not required, it is also a good
idea to register any extensions used by this format.

Once the plugin has been imported, it can be used:

.. code-block:: python
Once the plugin has been imported, it can be used::

from PIL import Image
import SpamImagePlugin
Expand Down Expand Up @@ -169,9 +167,7 @@ The raw decoder
The ``raw`` decoder is used to read uncompressed data from an image file. It
can be used with most uncompressed file formats, such as PPM, BMP, uncompressed
TIFF, and many others. To use the raw decoder with the
:py:func:`PIL.Image.frombytes` function, use the following syntax:

.. code-block:: python
:py:func:`PIL.Image.frombytes` function, use the following syntax::

image = Image.frombytes(
mode, size, data, "raw",
Expand Down Expand Up @@ -281,9 +277,7 @@ decoder that can be used to read various packed formats into a floating point
image memory.

To use the bit decoder with the :py:func:`PIL.Image.frombytes` function, use
the following syntax:

.. code-block:: python
the following syntax::

image = Image.frombytes(
mode, size, data, "bit",
Expand Down
40 changes: 10 additions & 30 deletions docs/reference/Image.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ Open, rotate, and display an image (using the default viewer)

The following script loads an image, rotates it 45 degrees, and displays it
using an external viewer (usually xv on Unix, and the Paint program on
Windows).

.. code-block:: python
Windows). ::

from PIL import Image
with Image.open("hopper.jpg") as im:
Expand All @@ -29,9 +27,7 @@ Create thumbnails
^^^^^^^^^^^^^^^^^

The following script creates nice thumbnails of all JPEG images in the
current directory preserving aspect ratios with 128x128 max resolution.

.. code-block:: python
current directory preserving aspect ratios with 128x128 max resolution. ::

from PIL import Image
import glob, os
Expand Down Expand Up @@ -127,9 +123,7 @@ methods. Unless otherwise stated, all methods return a new instance of the
.. automethod:: PIL.Image.Image.convert

The following example converts an RGB image (linearly calibrated according to
ITU-R 709, using the D65 luminant) to the CIE XYZ color space:

.. code-block:: python
ITU-R 709, using the D65 luminant) to the CIE XYZ color space::

rgb2xyz = (
0.412453, 0.357580, 0.180423, 0,
Expand All @@ -140,9 +134,7 @@ ITU-R 709, using the D65 luminant) to the CIE XYZ color space:
.. automethod:: PIL.Image.Image.copy
.. automethod:: PIL.Image.Image.crop

This crops the input image with the provided coordinates:

.. code-block:: python
This crops the input image with the provided coordinates::

from PIL import Image

Expand All @@ -162,9 +154,7 @@ This crops the input image with the provided coordinates:
.. automethod:: PIL.Image.Image.entropy
.. automethod:: PIL.Image.Image.filter

This blurs the input image using a filter from the ``ImageFilter`` module:

.. code-block:: python
This blurs the input image using a filter from the ``ImageFilter`` module::

from PIL import Image, ImageFilter

Expand All @@ -176,9 +166,7 @@ This blurs the input image using a filter from the ``ImageFilter`` module:
.. automethod:: PIL.Image.Image.frombytes
.. automethod:: PIL.Image.Image.getbands

This helps to get the bands of the input image:

.. code-block:: python
This helps to get the bands of the input image::

from PIL import Image

Expand All @@ -187,9 +175,7 @@ This helps to get the bands of the input image:

.. automethod:: PIL.Image.Image.getbbox

This helps to get the bounding box coordinates of the input image:

.. code-block:: python
This helps to get the bounding box coordinates of the input image::

from PIL import Image

Expand Down Expand Up @@ -217,9 +203,7 @@ This helps to get the bounding box coordinates of the input image:
.. automethod:: PIL.Image.Image.remap_palette
.. automethod:: PIL.Image.Image.resize

This resizes the given image from ``(width, height)`` to ``(width/2, height/2)``:

.. code-block:: python
This resizes the given image from ``(width, height)`` to ``(width/2, height/2)``::

from PIL import Image

Expand All @@ -231,9 +215,7 @@ This resizes the given image from ``(width, height)`` to ``(width/2, height/2)``

.. automethod:: PIL.Image.Image.rotate

This rotates the input image by ``theta`` degrees counter clockwise:

.. code-block:: python
This rotates the input image by ``theta`` degrees counter clockwise::

from PIL import Image

Expand All @@ -256,9 +238,7 @@ This rotates the input image by ``theta`` degrees counter clockwise:
.. automethod:: PIL.Image.Image.transpose

This flips the input image by using the :data:`Transpose.FLIP_LEFT_RIGHT`
method.

.. code-block:: python
method. ::

from PIL import Image

Expand Down
18 changes: 6 additions & 12 deletions docs/reference/ImageDraw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ For a more advanced drawing library for PIL, see the `aggdraw module`_.
Example: Draw a gray cross over an image
----------------------------------------

.. code-block:: python
::

import sys
from PIL import Image, ImageDraw
Expand Down Expand Up @@ -78,7 +78,7 @@ libraries, and may not available in all PIL builds.
Example: Draw Partial Opacity Text
----------------------------------

.. code-block:: python
::

from PIL import Image, ImageDraw, ImageFont

Expand All @@ -105,7 +105,7 @@ Example: Draw Partial Opacity Text
Example: Draw Multiline Text
----------------------------

.. code-block:: python
::

from PIL import Image, ImageDraw, ImageFont

Expand Down Expand Up @@ -597,18 +597,14 @@ Methods
string due to kerning. If you need to adjust for kerning, include the following
character and subtract its length.

For example, instead of

.. code-block:: python
For example, instead of ::

hello = draw.textlength("Hello", font)
world = draw.textlength("World", font)
hello_world = hello + world # not adjusted for kerning
assert hello_world == draw.textlength("HelloWorld", font) # may fail

use

.. code-block:: python
use ::

hello = draw.textlength("HelloW", font) - draw.textlength(
"W", font
Expand All @@ -617,9 +613,7 @@ Methods
hello_world = hello + world # adjusted for kerning
assert hello_world == draw.textlength("HelloWorld", font) # True

or disable kerning with (requires libraqm)

.. code-block:: python
or disable kerning with (requires libraqm) ::

hello = draw.textlength("Hello", font, features=["-kern"])
world = draw.textlength("World", font, features=["-kern"])
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ImageEnhance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ for image enhancement.
Example: Vary the sharpness of an image
---------------------------------------

.. code-block:: python
::

from PIL import ImageEnhance

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ImageFile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ and **xmllib** modules.
Example: Parse an image
-----------------------

.. code-block:: python
::

from PIL import ImageFile

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ImageFilter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ filters, which can be be used with the :py:meth:`Image.filter()
Example: Filter an image
------------------------

.. code-block:: python
::

from PIL import ImageFilter

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ImageFont.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ the imToolkit package.
Example
-------

.. code-block:: python
::

from PIL import ImageFont, ImageDraw

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ImageMath.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ an expression string and one or more images.
Example: Using the :py:mod:`~PIL.ImageMath` module
--------------------------------------------------

.. code-block:: python
::

from PIL import Image, ImageMath

Expand Down
4 changes: 1 addition & 3 deletions docs/reference/ImagePath.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ vector data. Path objects can be passed to the methods on the
.. py:method:: PIL.ImagePath.Path.transform(matrix)

Transforms the path in place, using an affine transform. The matrix is a
6-tuple (a, b, c, d, e, f), and each point is mapped as follows:

.. code-block:: python
6-tuple (a, b, c, d, e, f), and each point is mapped as follows::

xOut = xIn * a + yIn * b + c
yOut = xIn * d + yIn * e + f
2 changes: 1 addition & 1 deletion docs/reference/ImageSequence.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ iterate over the frames of an image sequence.
Extracting frames from an animation
-----------------------------------

.. code-block:: python
::

from PIL import Image, ImageSequence

Expand Down
4 changes: 1 addition & 3 deletions docs/reference/ImageWin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ Windows.

ImageWin can be used with PythonWin and other user interface toolkits that
provide access to Windows device contexts or window handles. For example,
Tkinter makes the window handle available via the winfo_id method:

.. code-block:: python
Tkinter makes the window handle available via the winfo_id method::

from PIL import ImageWin

Expand Down
8 changes: 2 additions & 6 deletions docs/reference/PixelAccess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ Example
-------

The following script loads an image, accesses one pixel from it, then
changes it.

.. code-block:: python
changes it. ::

from PIL import Image

Expand All @@ -35,9 +33,7 @@ Results in the following::
(23, 24, 68)
(0, 0, 0)

Access using negative indexes is also possible.

.. code-block:: python
Access using negative indexes is also possible. ::

px[-1, -1] = (0, 0, 0)
print(px[-1, -1])
Expand Down
8 changes: 2 additions & 6 deletions docs/reference/PyAccess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ The :py:mod:`~PIL.PyAccess` module provides a CFFI/Python implementation of the
Example
-------

The following script loads an image, accesses one pixel from it, then changes it.

.. code-block:: python
The following script loads an image, accesses one pixel from it, then changes it. ::

from PIL import Image

Expand All @@ -34,9 +32,7 @@ Results in the following::
(23, 24, 68)
(0, 0, 0)

Access using negative indexes is also possible.

.. code-block:: python
Access using negative indexes is also possible. ::

px[-1, -1] = (0, 0, 0)
print(px[-1, -1])
Expand Down
Loading