miurahr / py7zr

7zip in python3 with ZStandard, PPMd, LZMA2, LZMA1, Delta, BCJ, BZip2, and Deflate compressions, and AES encryption.

Home Page:https://pypi.org/project/py7zr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

discussion: Using Path instead of PurePath

mmngreco opened this issue · comments

Just to don't messing up the PR ( #513) with another issue, I hope you guys find this issue ok.

@mmngreco: In addition, looking at the code, I was wondering why not use Path instead of
PurePath? With Path, you can use .resolve(), .expanduser(),
.absolute(), and many other methods that may replace (I think) functions
entirely (like canonical_path). But this probably should be placed in another
issue.

@miurahr In my understanding, when using Path , it will access actuall filesystem, and can be failed by file system error.
A path in archive should not be access to actualll path except for extracting or archiveing. It is why I use PurePath instead of Path for internal path handling that come from archive meta data.

In case it helps here is my 5cents: both Path and PurePath can be used for path manipulation, but the main difference is that Path also provides methods for filesystem operations (I/O operations) by retrieving the concrete path based on your OS. However, these filesystem operations are only invoked when you explicitly call them.

So, it doesn't matter if you are referencing an existent or non-existent file or directory; Path won't fail (for example you can do some wild things like instantiate a WindowsPath in Linux and use it to do some path manipulations but can't be use it to perform I/O operations).

In the case of canonical_path, as far as I understood, it assumes a concrete path (PosixPath), so using Path methods might be more efficient and avoid reinventing the wheel. Let me know if I'm mistaken in anything above.

We may have a chance to use Path in topic branch and test it on several platforms in unit and integrate tests.
When it gives any wrong things, we can change it.