-
-
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
Handle pathlib.Path in FreeTypeFont #7578
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ae7958f
Handle pathlib.Path in FreeTypeFont
radarhere 9e8edb4
Added type hint
radarhere 4bc3655
Corrected type hint
radarhere 13c1d75
Use enum in type hint
radarhere 984700b
fix documentation link to PIL.ImageFont.Layout
nulano ea680d9
Merge pull request #21 from nulano/font
radarhere 9a6c47a
Merge branch 'main' into font
radarhere d042c4b
Added typing.IO to type hint
radarhere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm looking at
_util.is_path
, it checksisinstance(f, (bytes, str, Path))
, so bytes are also handled as paths, but next I see:else: load_from_bytes(font)
.Do we really want consider bytes as paths? I believe this is obsolete in Python3
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.
#258 was the original request for bytes as paths.
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.
I assume
load_from_bytes
is unreachable here, so we need to remove it, or provide a way to reach itThere 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.
I think it's reachable. The logic hasn't changed since
load_from_bytes()
was added in #3785.If it is a path, then pass the path to the C layer. If we're on Windows and the path is not ASCII, then open a file pointer to the path and read the contents of the file pointer with
load_from_bytes()
.If it is not a path, then it is a file pointer, read the contents of the file pointer with
load_from_bytes()
.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.
Ok, I see. I believe there is misnaming here, since f is not a bytes, it's file object.
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.
Oh right, I remember figuring that out after being confused in the past.
Should
typing.BinaryIO
be added to the type annotation then?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.
Yep, I've pushed a commit. Testing in PyCharm, I find it also includes
io.BytesIO
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.
@radarhere I see you've used
typing.IO
. This causes a mypy error, see #7642.Testing with both PyCharm and mypy, I find that a
io.BytesIO
value is accepted for atyping.BinaryIO
type hint (which seems correct here), so I'm not sure I understand your last message.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.
I think I was concerned about strings being used, but looking now, that doesn't appear to be a problem.