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
zipp.Path
is not Path-like enough for open
#110
Comments
Thanks for the report, especially laying out your observed and expected behavior! It's true that It's conceivable that In light of these other use-cases, does that change your expectations at all? What is the use-case that led you to have this expectation (why might someone else have this same expectation)? |
I have code that expects a In case the code receives a path that points to a zip file (and not a folder), it will continue with def transparent_unzip(recording: Path) -> Path:
if zipfile.is_zipfile(recording):
return zipp.Path(recording)
else:
return recording
def handle(folder_or_zip: Path):
recording = transparent_unzip(folder_or_zip)
schema = (recording / "marker").read_text()
... Out-of Scope Expectation
This statement would imply that e.g. files in It is navigating out of the zip ( Just Good Enough Scope ExpectationSo yes, |
Today I bumped onto another occurrence of the same behavior: extracting an image from a zip file: import zipp
root = zipp.Path("/path/to.zip")
import PIL.Image
with Image.open(root / "image.png") as img:
... This |
This use-case wouldn't be solved by making the root object Path-like. What could How does this new expectation affect your thinking about the original concern? |
I'm not sure if this is a problem with
open
not recognizingzipp.Path
or withzipp.Path
not implementing the right interface.But we can observe a mysterious incompatibility between
zipp.Path
and standard library functions.Disclaimer: I realize a more thorough type-analytical paper could probably be written about the relations between
zipp.Path
andpathlib.Path
, describing Liskov's Substitution Principle and including some in-depth type-theory and category theoretical proofs, but I'm not there yet :).Observed behavior:
Expected behavior:
The text was updated successfully, but these errors were encountered: