Skip to content

Commit

Permalink
Merge pull request #2100 from radarhere/flake8
Browse files Browse the repository at this point in the history
Flake8 and whitespace fixes
  • Loading branch information
hugovk committed Sep 3, 2016
2 parents b9a05b8 + 572a3d9 commit 6009e86
Show file tree
Hide file tree
Showing 41 changed files with 178 additions and 176 deletions.
118 changes: 59 additions & 59 deletions CHANGES.rst

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ def convert(self, mode=None, matrix=None, dither=None,
try:
t = trns_im.palette.getcolor(t)
except:
raise ValueError("Couldn't allocate a palette "+
raise ValueError("Couldn't allocate a palette " +
"color for transparency")
trns_im.putpixel((0, 0), t)

Expand Down
6 changes: 3 additions & 3 deletions PIL/ImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def load(self):
if n < 0:
break
b = b[n:]

# Need to cleanup here to prevent leaks in PyPy
decoder.cleanup()

Expand Down Expand Up @@ -473,7 +473,7 @@ def _save(im, fp, tile, bufsize=0):
e.setimage(im.im, b)
if e.pushes_fd:
e.setfd(fp)
l,s = e.encode_to_pyfd()
l, s = e.encode_to_pyfd()
else:
while True:
l, s, d = e.encode(bufsize)
Expand All @@ -492,7 +492,7 @@ def _save(im, fp, tile, bufsize=0):
e.setimage(im.im, b)
if e.pushes_fd:
e.setfd(fp)
l,s = e.encode_to_pyfd()
l, s = e.encode_to_pyfd()
else:
s = e.encode_to_file(fh, bufsize)
if s < 0:
Expand Down
4 changes: 2 additions & 2 deletions PIL/Jpeg2KImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _parse_jp2_header(fp):
mode = None
bpc = None
nc = None

hio = io.BytesIO(header)
while True:
lbox, tbox = struct.unpack('>I4s', hio.read(8))
Expand Down Expand Up @@ -144,7 +144,7 @@ def _parse_jp2_header(fp):

if size is None or mode is None:
raise SyntaxError("Malformed jp2 header")

return (size, mode)

##
Expand Down
2 changes: 1 addition & 1 deletion PIL/TiffTags.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def lookup(tag):
45056: ("MPFVersion", UNDEFINED, 1),
45057: ("NumberOfImages", LONG, 1),
45058: ("MPEntry", UNDEFINED, 1),
45059: ("ImageUIDList", UNDEFINED, 0), # UNDONE, check
45059: ("ImageUIDList", UNDEFINED, 0), # UNDONE, check
45060: ("TotalFrames", LONG, 1),
45313: ("MPIndividualNum", LONG, 1),
45569: ("PanOrientation", LONG, 1),
Expand Down
1 change: 1 addition & 0 deletions PIL/XVThumbImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
for b in range(4):
PALETTE = PALETTE + (o8((r*255)//7)+o8((g*255)//7)+o8((b*255)//3))


def _accept(prefix):
return prefix[:6] == _MAGIC

Expand Down
2 changes: 1 addition & 1 deletion PIL/_tkinter_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Tested with packages at https://bitbucket.org/pypy/pypy/downloads.
# PyPies 1.6, 2.0 do not have tkinter built in. PyPy3-2.3.1 gives an
# OSError trying to import tkinter. Otherwise:
try: # PyPy 5.1, 4.0.0, 2.6.1, 2.6.0
try: # PyPy 5.1, 4.0.0, 2.6.1, 2.6.0
TKINTER_LIB = tk.tklib_cffi.__file__
except AttributeError:
# PyPy3 2.4, 2.1-beta1; PyPy 2.5.1, 2.5.0, 2.4.0, 2.3, 2.2, 2.1
Expand Down
2 changes: 1 addition & 1 deletion Tests/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Install::
pip install coverage nose

If you're using Python 2.6, there's one additional dependency::

pip install unittest2

Execution
Expand Down
1 change: 0 additions & 1 deletion Tests/test_file_eps.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def test_cmyk(self):
target = Image.open('Tests/images/pil_sample_rgb.jpg')
self.assert_image_similar(cmyk_image, target, 10)


def test_file_object(self):
# issue 479
image1 = Image.open(file1)
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_jpeg2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_sanity(self):

im = Image.open('Tests/images/test-card-lossless.jp2')
px = im.load()
self.assertEqual(px[0,0], (0, 0, 0))
self.assertEqual(px[0, 0], (0, 0, 0))
self.assertEqual(im.mode, 'RGB')
self.assertEqual(im.size, (640, 480))
self.assertEqual(im.format, 'JPEG2000')
Expand Down
6 changes: 3 additions & 3 deletions Tests/test_file_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,11 @@ def test_roundtrip_tiff_uint16(self):

tmpfile = self.tempfile("temp.tif")
im.save(tmpfile)

reloaded = Image.open(tmpfile)

self.assert_image_equal(im, reloaded)


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion Tests/test_image_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def make_case(self, mode, size, color):
rectangle((0, 0, size[0] // 2 - 1, size[1] // 2 - 1), color)
rectangle((size[0] // 2, size[1] // 2, size[0], size[1]), color)

return Image.merge(mode, [case] * len(mode))
return Image.merge(mode, [case] * len(mode))

def make_sample(self, data, size):
"""Restores a sample image from given data string which contains
Expand Down
1 change: 1 addition & 0 deletions Tests/test_imagecms.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def assert_truncated_tuple_equal(tup1, tup2, digits=10):
# Helper function to reduce precision of tuples of floats
# recursively and then check equality.
power = 10 ** digits

def truncate_tuple(tuple_or_float):
return tuple(
truncate_tuple(val) if isinstance(val, tuple)
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_imageops.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_pil163(self):
def test_scale(self):
# Test the scaling function
i = hopper("L").resize((50, 50))

with self.assertRaises(ValueError):
ImageOps.scale(i, -1)

Expand Down
7 changes: 4 additions & 3 deletions Tests/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
# the repr is that of a PIL.Image. Size and shape are 1 and (), not the
# size and shape of the array. This causes failures in several tests.
SKIP_NUMPY_ON_PYPY = hasattr(sys, 'pypy_version_info') and (
sys.pypy_version_info <= (5,3,1,'final',0))
sys.pypy_version_info <= (5, 3, 1, 'final', 0))


class TestNumpy(PillowTestCase):

Expand Down Expand Up @@ -137,14 +138,14 @@ def test_1bit(self):
numpy.testing.assert_array_equal(arr, arr_back)

def test_save_tiff_uint16(self):
# Tests that we're getting the pixel value in the right byte order.
# Tests that we're getting the pixel value in the right byte order.
pixel_value = 0x1234
a = numpy.array([pixel_value] * TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1], dtype=numpy.uint16)
a.shape = TEST_IMAGE_SIZE
img = Image.fromarray(a)

img_px = img.load()
self.assertEqual(img_px[0,0], pixel_value)
self.assertEqual(img_px[0, 0], pixel_value)

@unittest.skipIf(SKIP_NUMPY_ON_PYPY, "numpy.array(Image) is flaky on PyPy")
def test_to_array(self):
Expand Down
8 changes: 4 additions & 4 deletions _imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,17 +364,17 @@ getbands(const char* mode)
static void*
getlist(PyObject* arg, Py_ssize_t* length, const char* wrong_length, int type)
{
/* - allocates and returns a c array of the items in the
/* - allocates and returns a c array of the items in the
python sequence arg.
- the size of the returned array is in length
- all of the arg items must be numeric items of the type
- all of the arg items must be numeric items of the type
specified in type
- sequence length is checked against the length parameter IF
an error parameter is passed in wrong_length
- caller is responsible for freeing the memory
- caller is responsible for freeing the memory
*/

Py_ssize_t i, n;
Py_ssize_t i, n;
int itemp;
double dtemp;
void* list;
Expand Down
8 changes: 4 additions & 4 deletions _imagingft.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw)
PyMem_Free(filename);
return NULL;
}

self->face = NULL;

if (filename && font_bytes_size <= 0) {
self->font_bytes = NULL;
error = FT_New_Face(library, filename, index, &self->face);
Expand Down Expand Up @@ -246,11 +246,11 @@ font_getsize(FontObject* self, PyObject* args)
y_max = bbox.yMax;
if (bbox.yMin < y_min)
y_min = bbox.yMin;

/* find max distance of baseline from top */
if (face->glyph->metrics.horiBearingY > yoffset)
yoffset = face->glyph->metrics.horiBearingY;

last_index = index;
FT_Done_Glyph(glyph);
}
Expand Down
4 changes: 2 additions & 2 deletions _imagingmorph.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ get_on_pixels(PyObject *self, PyObject* args)
int row_idx, col_idx;
int width, height;
PyObject *ret = PyList_New(0);

if (!PyArg_ParseTuple(args, "n", &i0)) {
PyErr_SetString(PyExc_RuntimeError, "Argument parsing problem");

Expand All @@ -241,7 +241,7 @@ get_on_pixels(PyObject *self, PyObject* args)
rows = img->image8;
width = img->xsize;
height = img->ysize;

for (row_idx=0; row_idx < height; row_idx++) {
UINT8 *row = rows[row_idx];
for (col_idx=0; col_idx<width; col_idx++) {
Expand Down
2 changes: 1 addition & 1 deletion depends/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ e.g.::
$ source ~/vpy27/bin/activate
$ make install
$ make test

2 changes: 1 addition & 1 deletion depends/alpine_Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN apk --no-cache add python \
RUN apk --no-cache add git \
bash \
sudo

RUN git clone https://github.com/python-pillow/Pillow.git /Pillow
RUN pip install virtualenv && virtualenv /vpy && source /vpy/bin/activate && pip install nose

Expand Down
2 changes: 1 addition & 1 deletion docs/handbook/image-file-formats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ explicitly.
Fully supported formats
-----------------------

.. contents::
.. contents::

BMP
^^^
Expand Down
6 changes: 3 additions & 3 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ Building on Linux
^^^^^^^^^^^^^^^^^

If you didn't build Python from source, make sure you have Python's
development libraries installed.
development libraries installed.

In Debian or Ubuntu::

Expand All @@ -295,10 +295,10 @@ Or for Python 3::
In Fedora, the command is::

$ sudo dnf install python-devel redhat-rpm-config

Or for Python 3::

$ sudo dnf install python3-devel redhat-rpm-config
$ sudo dnf install python3-devel redhat-rpm-config

.. Note:: ``redhat-rpm-config`` is required on Fedora 23, but not earlier versions.

Expand Down
12 changes: 6 additions & 6 deletions docs/reference/PixelAccess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The following script loads an image, accesses one pixel from it, then
changes it.

.. code-block:: python
from PIL import Image
im = Image.open('hopper.jpg')
px = im.load()
Expand All @@ -28,7 +28,7 @@ Results in the following::
(23, 24, 68)
(0, 0, 0)



:py:class:`PixelAccess` Class
-----------------------------------
Expand All @@ -43,9 +43,9 @@ Results in the following::

:param xy: The pixel coordinate, given as (x, y).
:param value: The pixel value.

.. method:: __getitem__(self, xy):

Returns the pixel at x,y. The pixel is returned as a single
value for single band images or a tuple for multiple band
images
Expand All @@ -62,9 +62,9 @@ Results in the following::

:param xy: The pixel coordinate, given as (x, y).
:param value: The pixel value.

.. method:: getpixel(self, xy):

Returns the pixel at x,y. The pixel is returned as a single
value for single band images or a tuple for multiple band
images
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/PyAccess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Example
The following script loads an image, accesses one pixel from it, then changes it.

.. code-block:: python
from PIL import Image
im = Image.open('hopper.jpg')
px = im.load()
Expand All @@ -29,7 +29,7 @@ Results in the following::
(23, 24, 68)
(0, 0, 0)



:py:class:`PyAccess` Class
--------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/TiffTags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ metadata tag numbers, names, and type information.
:param type: Integer type from :py:attr:`PIL.TiffTags.TYPES`
:param length: Array length: 0 == variable, 1 == single value, n = fixed
:param enum: Dict of name:integer value options for an enumeration

.. method:: cvt_enum(self, value)

:param value: The enumerated value name
Expand Down
4 changes: 2 additions & 2 deletions encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ _encode_to_pyfd(ImagingEncoderObject* encoder, PyObject* args)

status = encoder->encode(encoder->im, &encoder->state,
(UINT8*) NULL, 0);

result = Py_BuildValue("ii", status, encoder->state.errcode);

return result;
Expand Down Expand Up @@ -291,7 +291,7 @@ _setfd(ImagingEncoderObject* encoder, PyObject* args)

Py_XINCREF(fd);
state->fd = fd;

Py_INCREF(Py_None);
return Py_None;
}
Expand Down

0 comments on commit 6009e86

Please sign in to comment.