diff --git a/src/PIL/ImageQt.py b/src/PIL/ImageQt.py index bdfe3886c..b747781c5 100644 --- a/src/PIL/ImageQt.py +++ b/src/PIL/ImageQt.py @@ -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) diff --git a/src/PIL/PdfParser.py b/src/PIL/PdfParser.py index 66d6ecfb1..7216e5b95 100644 --- a/src/PIL/PdfParser.py +++ b/src/PIL/PdfParser.py @@ -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 diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index 7859de531..30d5e620e 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -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) diff --git a/src/PIL/_util.py b/src/PIL/_util.py index e6989d69d..5828c2c24 100644 --- a/src/PIL/_util.py +++ b/src/PIL/_util.py @@ -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.