mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-27 12:33:41 +03:00
Replace isStringType(t) with isinstance(t, str)
Co-Authored-By: Jon Dufresne <jon.dufresne@gmail.com>
This commit is contained in:
parent
e118de943d
commit
3e24c5fea4
|
@ -4,26 +4,6 @@ from .helper import PillowTestCase, unittest
|
||||||
|
|
||||||
|
|
||||||
class TestUtil(PillowTestCase):
|
class TestUtil(PillowTestCase):
|
||||||
def test_is_string_type(self):
|
|
||||||
# Arrange
|
|
||||||
color = "red"
|
|
||||||
|
|
||||||
# Act
|
|
||||||
it_is = _util.isStringType(color)
|
|
||||||
|
|
||||||
# Assert
|
|
||||||
self.assertTrue(it_is)
|
|
||||||
|
|
||||||
def test_is_not_string_type(self):
|
|
||||||
# Arrange
|
|
||||||
color = (255, 0, 0)
|
|
||||||
|
|
||||||
# Act
|
|
||||||
it_is_not = _util.isStringType(color)
|
|
||||||
|
|
||||||
# Assert
|
|
||||||
self.assertFalse(it_is_not)
|
|
||||||
|
|
||||||
def test_is_path(self):
|
def test_is_path(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
fp = "filename.ext"
|
fp = "filename.ext"
|
||||||
|
|
|
@ -43,7 +43,7 @@ from pathlib import Path
|
||||||
# Use __version__ instead.
|
# Use __version__ instead.
|
||||||
from . import ImageMode, TiffTags, __version__, _plugins
|
from . import ImageMode, TiffTags, __version__, _plugins
|
||||||
from ._binary import i8, i32le
|
from ._binary import i8, i32le
|
||||||
from ._util import deferred_error, isPath, isStringType
|
from ._util import deferred_error, isPath
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -1466,7 +1466,7 @@ class Image:
|
||||||
raise ValueError("cannot determine region size; use 4-item box")
|
raise ValueError("cannot determine region size; use 4-item box")
|
||||||
box += (box[0] + size[0], box[1] + size[1])
|
box += (box[0] + size[0], box[1] + size[1])
|
||||||
|
|
||||||
if isStringType(im):
|
if isinstance(im, str):
|
||||||
from . import ImageColor
|
from . import ImageColor
|
||||||
|
|
||||||
im = ImageColor.getcolor(im, self.mode)
|
im = ImageColor.getcolor(im, self.mode)
|
||||||
|
@ -2120,7 +2120,7 @@ class Image:
|
||||||
"""
|
"""
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
if isStringType(channel):
|
if isinstance(channel, str):
|
||||||
try:
|
try:
|
||||||
channel = self.getbands().index(channel)
|
channel = self.getbands().index(channel)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -2447,7 +2447,7 @@ def new(mode, size, color=0):
|
||||||
# don't initialize
|
# don't initialize
|
||||||
return Image()._new(core.new(mode, size))
|
return Image()._new(core.new(mode, size))
|
||||||
|
|
||||||
if isStringType(color):
|
if isinstance(color, str):
|
||||||
# css3-style specifier
|
# css3-style specifier
|
||||||
|
|
||||||
from . import ImageColor
|
from . import ImageColor
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL._util import isStringType
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PIL import _imagingcms
|
from PIL import _imagingcms
|
||||||
|
@ -159,7 +158,7 @@ class ImageCmsProfile:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if isStringType(profile):
|
if isinstance(profile, str):
|
||||||
self._set(core.profile_open(profile), profile)
|
self._set(core.profile_open(profile), profile)
|
||||||
elif hasattr(profile, "read"):
|
elif hasattr(profile, "read"):
|
||||||
self._set(core.profile_frombytes(profile.read()))
|
self._set(core.profile_frombytes(profile.read()))
|
||||||
|
|
|
@ -34,7 +34,6 @@ import math
|
||||||
import numbers
|
import numbers
|
||||||
|
|
||||||
from . import Image, ImageColor
|
from . import Image, ImageColor
|
||||||
from ._util import isStringType
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -107,13 +106,13 @@ class ImageDraw:
|
||||||
ink = self.ink
|
ink = self.ink
|
||||||
else:
|
else:
|
||||||
if ink is not None:
|
if ink is not None:
|
||||||
if isStringType(ink):
|
if isinstance(ink, str):
|
||||||
ink = ImageColor.getcolor(ink, self.mode)
|
ink = ImageColor.getcolor(ink, self.mode)
|
||||||
if self.palette and not isinstance(ink, numbers.Number):
|
if self.palette and not isinstance(ink, numbers.Number):
|
||||||
ink = self.palette.getcolor(ink)
|
ink = self.palette.getcolor(ink)
|
||||||
ink = self.draw.draw_ink(ink)
|
ink = self.draw.draw_ink(ink)
|
||||||
if fill is not None:
|
if fill is not None:
|
||||||
if isStringType(fill):
|
if isinstance(fill, str):
|
||||||
fill = ImageColor.getcolor(fill, self.mode)
|
fill = ImageColor.getcolor(fill, self.mode)
|
||||||
if self.palette and not isinstance(fill, numbers.Number):
|
if self.palette and not isinstance(fill, numbers.Number):
|
||||||
fill = self.palette.getcolor(fill)
|
fill = self.palette.getcolor(fill)
|
||||||
|
|
|
@ -21,7 +21,6 @@ import functools
|
||||||
import operator
|
import operator
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
from ._util import isStringType
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# helpers
|
# helpers
|
||||||
|
@ -39,7 +38,7 @@ def _border(border):
|
||||||
|
|
||||||
|
|
||||||
def _color(color, mode):
|
def _color(color, mode):
|
||||||
if isStringType(color):
|
if isinstance(color, str):
|
||||||
from . import ImageColor
|
from . import ImageColor
|
||||||
|
|
||||||
color = ImageColor.getcolor(color, mode)
|
color = ImageColor.getcolor(color, mode)
|
||||||
|
|
|
@ -41,7 +41,6 @@ import warnings
|
||||||
|
|
||||||
from . import Image, ImageFile, TiffImagePlugin
|
from . import Image, ImageFile, TiffImagePlugin
|
||||||
from ._binary import i8, i16be as i16, i32be as i32, o8
|
from ._binary import i8, i16be as i16, i32be as i32, o8
|
||||||
from ._util import isStringType
|
|
||||||
from .JpegPresets import presets
|
from .JpegPresets import presets
|
||||||
|
|
||||||
# __version__ is deprecated and will be removed in a future version. Use
|
# __version__ is deprecated and will be removed in a future version. Use
|
||||||
|
@ -638,7 +637,7 @@ def _save(im, fp, filename):
|
||||||
else:
|
else:
|
||||||
if subsampling in presets:
|
if subsampling in presets:
|
||||||
subsampling = presets[subsampling].get("subsampling", -1)
|
subsampling = presets[subsampling].get("subsampling", -1)
|
||||||
if isStringType(qtables) and qtables in presets:
|
if isinstance(qtables, str) and qtables in presets:
|
||||||
qtables = presets[qtables].get("quantization")
|
qtables = presets[qtables].get("quantization")
|
||||||
|
|
||||||
if subsampling == "4:4:4":
|
if subsampling == "4:4:4":
|
||||||
|
@ -659,7 +658,7 @@ def _save(im, fp, filename):
|
||||||
def validate_qtables(qtables):
|
def validate_qtables(qtables):
|
||||||
if qtables is None:
|
if qtables is None:
|
||||||
return qtables
|
return qtables
|
||||||
if isStringType(qtables):
|
if isinstance(qtables, str):
|
||||||
try:
|
try:
|
||||||
lines = [
|
lines = [
|
||||||
int(num)
|
int(num)
|
||||||
|
|
|
@ -4,10 +4,6 @@ import sys
|
||||||
py36 = sys.version_info[0:2] >= (3, 6)
|
py36 = sys.version_info[0:2] >= (3, 6)
|
||||||
|
|
||||||
|
|
||||||
def isStringType(t):
|
|
||||||
return isinstance(t, str)
|
|
||||||
|
|
||||||
|
|
||||||
if py36:
|
if py36:
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user