[Private] function names should be snake_case

This commit is contained in:
Hugo van Kemenade 2022-04-10 21:20:48 +03:00
parent d3c9a6504e
commit d241e38120
6 changed files with 21 additions and 21 deletions

View File

@ -8,7 +8,7 @@ def test_is_path():
fp = "filename.ext" fp = "filename.ext"
# Act # Act
it_is = _util.isPath(fp) it_is = _util.is_path(fp)
# Assert # Assert
assert it_is assert it_is
@ -21,7 +21,7 @@ def test_path_obj_is_path():
test_path = Path("filename.ext") test_path = Path("filename.ext")
# Act # Act
it_is = _util.isPath(test_path) it_is = _util.is_path(test_path)
# Assert # Assert
assert it_is assert it_is
@ -33,7 +33,7 @@ def test_is_not_path(tmp_path):
pass pass
# Act # Act
it_is_not = _util.isPath(fp) it_is_not = _util.is_path(fp)
# Assert # Assert
assert not it_is_not assert not it_is_not
@ -44,7 +44,7 @@ def test_is_directory():
directory = "Tests" directory = "Tests"
# Act # Act
it_is = _util.isDirectory(directory) it_is = _util.is_directory(directory)
# Assert # Assert
assert it_is assert it_is
@ -55,7 +55,7 @@ def test_is_not_directory():
text = "abc" text = "abc"
# Act # Act
it_is_not = _util.isDirectory(text) it_is_not = _util.is_directory(text)
# Assert # Assert
assert not it_is_not assert not it_is_not

View File

@ -50,7 +50,7 @@ except ImportError:
# Use __version__ instead. # Use __version__ instead.
from . import ImageMode, TiffTags, UnidentifiedImageError, __version__, _plugins from . import ImageMode, TiffTags, UnidentifiedImageError, __version__, _plugins
from ._binary import i32le, o32be, o32le from ._binary import i32le, o32be, o32le
from ._util import deferred_error, isPath from ._util import deferred_error, is_path
def __getattr__(name): def __getattr__(name):
@ -2251,7 +2251,7 @@ class Image:
if isinstance(fp, Path): if isinstance(fp, Path):
filename = str(fp) filename = str(fp)
open_fp = True open_fp = True
elif isPath(fp): elif is_path(fp):
filename = fp filename = fp
open_fp = True open_fp = True
elif fp == sys.stdout: elif fp == sys.stdout:
@ -2259,7 +2259,7 @@ class Image:
fp = sys.stdout.buffer fp = sys.stdout.buffer
except AttributeError: except AttributeError:
pass pass
if not filename and hasattr(fp, "name") and isPath(fp.name): if not filename and hasattr(fp, "name") and is_path(fp.name):
# only set the name for metadata purposes # only set the name for metadata purposes
filename = fp.name filename = fp.name
@ -3065,7 +3065,7 @@ def open(fp, mode="r", formats=None):
filename = "" filename = ""
if isinstance(fp, Path): if isinstance(fp, Path):
filename = str(fp.resolve()) filename = str(fp.resolve())
elif isPath(fp): elif is_path(fp):
filename = fp filename = fp
if filename: if filename:

View File

@ -33,7 +33,7 @@ import struct
import sys import sys
from . import Image from . import Image
from ._util import isPath from ._util import is_path
MAXBLOCK = 65536 MAXBLOCK = 65536
@ -99,7 +99,7 @@ class ImageFile(Image.Image):
self.decoderconfig = () self.decoderconfig = ()
self.decodermaxblock = MAXBLOCK self.decodermaxblock = MAXBLOCK
if isPath(fp): if is_path(fp):
# filename # filename
self.fp = open(fp, "rb") self.fp = open(fp, "rb")
self.filename = fp self.filename = fp

View File

@ -33,7 +33,7 @@ from enum import IntEnum
from io import BytesIO from io import BytesIO
from . import Image from . import Image
from ._util import isDirectory, isPath from ._util import is_directory, is_path
class Layout(IntEnum): class Layout(IntEnum):
@ -212,7 +212,7 @@ class FreeTypeFont:
"", size, index, encoding, self.font_bytes, layout_engine "", size, index, encoding, self.font_bytes, layout_engine
) )
if isPath(font): if is_path(font):
if sys.platform == "win32": if sys.platform == "win32":
font_bytes_path = font if isinstance(font, bytes) else font.encode() font_bytes_path = font if isinstance(font, bytes) else font.encode()
try: try:
@ -877,7 +877,7 @@ def truetype(font=None, size=10, index=0, encoding="", layout_engine=None):
try: try:
return freetype(font) return freetype(font)
except OSError: except OSError:
if not isPath(font): if not is_path(font):
raise raise
ttf_filename = os.path.basename(font) ttf_filename = os.path.basename(font)
@ -931,7 +931,7 @@ def load_path(filename):
:exception OSError: If the file could not be read. :exception OSError: If the file could not be read.
""" """
for directory in sys.path: for directory in sys.path:
if isDirectory(directory): if is_directory(directory):
if not isinstance(filename, str): if not isinstance(filename, str):
filename = filename.decode("utf-8") filename = filename.decode("utf-8")
try: try:

View File

@ -20,7 +20,7 @@ import sys
from io import BytesIO from io import BytesIO
from . import Image from . import Image
from ._util import isPath from ._util import is_path
qt_versions = [ qt_versions = [
["6", "PyQt6"], ["6", "PyQt6"],
@ -140,7 +140,7 @@ def _toqclass_helper(im):
if hasattr(im, "toUtf8"): if hasattr(im, "toUtf8"):
# FIXME - is this really the best way to do this? # FIXME - is this really the best way to do this?
im = str(im.toUtf8(), "utf-8") im = str(im.toUtf8(), "utf-8")
if isPath(im): if is_path(im):
im = Image.open(im) im = Image.open(im)
exclusive_fp = True exclusive_fp = True

View File

@ -2,13 +2,13 @@ import os
from pathlib import Path from pathlib import Path
def isPath(f): def is_path(f):
return isinstance(f, (bytes, str, Path)) return isinstance(f, (bytes, str, Path))
# Checks if an object is a string, and that it points to a directory. def is_directory(f):
def isDirectory(f): """Checks if an object is a string, and that it points to a directory."""
return isPath(f) and os.path.isdir(f) return is_path(f) and os.path.isdir(f)
class deferred_error: class deferred_error: