Merge pull request #3616 from wbadart/master

_util.isPath returns True for pathlib.Path objects
This commit is contained in:
Hugo 2019-02-20 11:48:12 +02:00 committed by GitHub
commit 8cd0432e65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -35,6 +35,18 @@ class TestUtil(PillowTestCase):
# Assert
self.assertTrue(it_is)
@unittest.skipIf(not _util.py36, 'os.path support for Paths added in 3.6')
def test_path_obj_is_path(self):
# Arrange
from pathlib import Path
test_path = Path('filename.ext')
# Act
it_is = _util.isPath(test_path)
# Assert
self.assertTrue(it_is)
def test_is_not_path(self):
# Arrange
filename = self.tempfile("temp.ext")

View File

@ -2,11 +2,18 @@ import os
import sys
py3 = sys.version_info.major >= 3
py36 = sys.version_info[0:2] >= (3, 6)
if py3:
def isStringType(t):
return isinstance(t, str)
if py36:
from pathlib import Path
def isPath(f):
return isinstance(f, (bytes, str, Path))
else:
def isPath(f):
return isinstance(f, (bytes, str))
else: