Skip to content

Removed unnecessary string length check#7560

Merged
hugovk merged 1 commit intopython-pillow:mainfrom
radarhere:string_length_check
Dec 21, 2023
Merged

Removed unnecessary string length check#7560
hugovk merged 1 commit intopython-pillow:mainfrom
radarhere:string_length_check

Conversation

@radarhere
Copy link
Member

#7244 added _string_length_check() in several locations, including TransposedFont.getlength().

Pillow/src/PIL/ImageFont.py

Lines 711 to 716 in 28c173f

def getlength(self, text, *args, **kwargs):
if self.orientation in (Image.Transpose.ROTATE_90, Image.Transpose.ROTATE_270):
msg = "text length is undefined for text rotated by 90 or 270 degrees"
raise ValueError(msg)
_string_length_check(text)
return self.font.getlength(text, *args, **kwargs)

However, getlength() is immediately called after the check, which itself calls _string_length_check().

So this check is unnecessary and can be removed.

@hugovk hugovk merged commit 0331d9d into python-pillow:main Dec 21, 2023
@radarhere radarhere deleted the string_length_check branch December 21, 2023 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants