-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added type hints #8125
Added type hints #8125
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -326,7 +326,7 @@ | |||||||
} | ||||||||
|
||||||||
|
||||||||
def _save(im: Image.Image, fp: IO[bytes], filename: str) -> None: | ||||||||
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: | ||||||||
try: | ||||||||
image_type, rawmode = SAVE[im.mode] | ||||||||
except KeyError as e: | ||||||||
|
@@ -341,6 +341,8 @@ | |||||||
# or: SyntaxError("not an IM file") | ||||||||
# 8 characters are used for "Name: " and "\r\n" | ||||||||
# Keep just the filename, ditch the potentially overlong path | ||||||||
if isinstance(filename, bytes): | ||||||||
filename = filename.decode("ascii") | ||||||||
Comment on lines
+344
to
+345
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this also fixing a bug? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In main at the moment, save handlers can receive strings or bytes as the filename. Line 2454 in 53e82e4
Lines 231 to 232 in 53e82e4
Part of this PR is propagating that out to some plugins that were only using strings. |
||||||||
name, ext = os.path.splitext(os.path.basename(filename)) | ||||||||
name = "".join([name[: 92 - len(ext)], ext]) | ||||||||
|
||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What triggered this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once i type hinted the
_save
method in this plugin, mypy reportedThis change fixes it. I can use a named tuple or something if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Named tuples are nice, but this is very localised so I think we're fine with a basic tuple here.