noqa some Py2/3 compat lines and others

This commit is contained in:
Hugo 2018-11-13 14:01:09 +02:00
parent f3c1f08f5b
commit c75910dbc3
4 changed files with 10 additions and 10 deletions

View File

@ -140,7 +140,7 @@ def _toqclass_helper(im):
if py3:
im = str(im.toUtf8(), "utf-8")
else:
im = unicode(im.toUtf8(), "utf-8")
im = unicode(im.toUtf8(), "utf-8") # noqa: F821
if isPath(im):
im = Image.open(im)

View File

@ -373,7 +373,7 @@ def pdf_repr(x):
elif isinstance(x, list):
return bytes(PdfArray(x))
elif ((py3 and isinstance(x, str)) or
(not py3 and isinstance(x, unicode))):
(not py3 and isinstance(x, unicode))): # noqa: F821
return pdf_repr(encode_text(x))
elif isinstance(x, bytes):
# XXX escape more chars? handle binary garbage

View File

@ -541,7 +541,7 @@ class ImageFileDirectory_v2(MutableMapping):
def _setitem(self, tag, value, legacy_api):
basetypes = (Number, bytes, str)
if not py3:
basetypes += unicode,
basetypes += unicode, # noqa: F821
info = TiffTags.lookup(tag)
values = [value] if isinstance(value, basetypes) else value
@ -623,13 +623,13 @@ class ImageFileDirectory_v2(MutableMapping):
from .TiffTags import TYPES
if func.__name__.startswith("load_"):
TYPES[idx] = func.__name__[5:].replace("_", " ")
_load_dispatch[idx] = size, func
_load_dispatch[idx] = size, func # noqa: F821
return func
return decorator
def _register_writer(idx):
def decorator(func):
_write_dispatch[idx] = func
_write_dispatch[idx] = func # noqa: F821
return func
return decorator
@ -638,9 +638,9 @@ class ImageFileDirectory_v2(MutableMapping):
idx, fmt, name = idx_fmt_name
TYPES[idx] = name
size = struct.calcsize("=" + fmt)
_load_dispatch[idx] = size, lambda self, data, legacy_api=True: (
_load_dispatch[idx] = size, lambda self, data, legacy_api=True: ( # noqa: F821
self._unpack("{}{}".format(len(data) // size, fmt), data))
_write_dispatch[idx] = lambda self, *values: (
_write_dispatch[idx] = lambda self, *values: ( # noqa: F821
b"".join(self._pack(fmt, value) for value in values))
list(map(_register_basic,
@ -1507,7 +1507,7 @@ def _save(im, fp, filename):
if tag not in TiffTags.LIBTIFF_CORE:
continue
if tag not in atts and tag not in blocklist:
if isinstance(value, str if py3 else unicode):
if isinstance(value, str if py3 else unicode): # noqa: F821
atts[tag] = value.encode('ascii', 'replace') + b"\0"
elif isinstance(value, IFDRational):
atts[tag] = float(value)

View File

@ -11,10 +11,10 @@ if py3:
return isinstance(f, (bytes, str))
else:
def isStringType(t):
return isinstance(t, basestring)
return isinstance(t, basestring) # noqa: F821
def isPath(f):
return isinstance(f, basestring)
return isinstance(f, basestring) # noqa: F821
# Checks if an object is a string, and that it points to a directory.