Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(types): get the os.PathLike type as correctly as possible#1227

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Byron merged 1 commit intogitpython-developers:mainfrommuggenhor:fix/pathlike-type
Apr 23, 2021
Merged

fix(types): get the os.PathLike type as correctly as possible#1227

Byron merged 1 commit intogitpython-developers:mainfrommuggenhor:fix/pathlike-type
Apr 23, 2021

Conversation

muggenhor
Copy link
Contributor

@muggenhormuggenhor commentedApr 23, 2021
edited
Loading

This should make our internal PathLike type compatible with Python < 3.6 and < 3.9.

Fixes#1219

This should make our internal PathLike type compatible with Python <3.6 and < 3.9.
@muggenhor
Copy link
ContributorAuthor

Switched away fromtry-except to explicit version checks because that seems to be the recommended stylepython/mypy#698

@muggenhormuggenhor mentioned this pull requestApr 23, 2021
@ByronByron merged commit9f12c8c intogitpython-developers:mainApr 23, 2021
@muggenhormuggenhor deleted the fix/pathlike-type branchApril 23, 2021 13:20
@Byron
Copy link
Member

Thanks, very elegant!

I find it interesting that all PathLike types seem to usestr in some way even though AFAIK these are to be decoded with some encoding from what the OS provides. As this encoding is unspecified or at least very dependent on knowledge about the OS and its settings, using a path based onstr can fail with some sort of decoding error.

@muggenhor
Copy link
ContributorAuthor

FYI: this is thetype annotation definition ofos.PathLike. So whatos.PathLike[str] means is: it has to be a type with an__fscache__(self) -> str method. So that's the method where any conversions should be performed.

Byron reacted with thumbs up emoji

@muggenhor
Copy link
ContributorAuthor

I find it interesting that all PathLike types seem to usestr in some way even though AFAIK these are to be decoded with some encoding from what the OS provides. As this encoding is unspecified or at least very dependent on knowledge about the OS and its settings, using a path based onstr can fail with some sort of decoding error.

Hmm. Does that mean you think it should acceptbytes in some locations too?

@Byron
Copy link
Member

Byron commentedApr 24, 2021
edited
Loading

Hmm. Does that mean you think it should accept bytes in some locations too?

I would refrain from doing anything that reduces convenience or being idiomatic or that is breaking just to gain correctness.
But I think that as it stands, GitPython will work fine until it doesn't because one tries to handle a path with characters that don't decode with the pre-configured default encoding. Right now this is UTF-8, certainly a decent choice. But it won't always work either.

To me the whole encoding topic in GitPython is a lost cause as correctness could (to my mind) only be achieved if the API doesn't use strings (with encoding) to handle them.

And by the looks of it, it's idiomatic to do that, too:

# py 3.8>>> type(os.listdir('.')[0])<class'str'>

Edit: On the bright side, I believe just today I had an epiphany which helps me to see a future for GitPython, leveraging it as a strength and not seeing it as a burden. So I hope this will change my mindset too when helping to maintain it in the midterm until such a future can be realized.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Python 3.5 failing with AttributeError: module 'os' has no attribute 'PathLike'
2 participants
@muggenhor@Byron

[8]ページ先頭

©2009-2025 Movatter.jp