-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-128584: Allow gzip mtime to be a datetime object #128589
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
base: main
Are you sure you want to change the base?
Conversation
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.
General triage comments. I'll dive into the actual implementation sometime soon.
Misc/NEWS.d/next/Library/2025-01-07-15-31-37.gh-issue-128584.RNjQh2.rst
Outdated
Show resolved
Hide resolved
Hi @ZeroIntensity, thank you for reviewing the PR. I've pushed a new commit which causes the relevant compress methods to raise a I'm highlighting this as it's an additional change not mentioned in the original issue or PR description. If you don't think it's appropriate for this PR then please let me know and I'll revert the commit. |
I think that makes sense. FYI, tests are failing on Windows. |
…f GzipFile._write_gzip_header to avoid file staying open on raising ValueError.
Hi @ZeroIntensity, is this ready to merge please? |
Sorry, I don't know enough about this part of the codebase to do a thorough review, nor do I have the sufficient permissions to merge this :( @picnixz, would you mind taking a look? |
I'm leaving until Friday, I can take a look at that time. |
@ZeroIntensity I couldn't find the PR to look at it before so in the future, if you want my review on a PR, just outright request it, it's fine for me! |
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.
Serhiy hinted that this would create a dependency between datetime and gzip (#128584 (comment)). I also agree that it's probably cleaner for the caller to call .timestamp()
before instead of doing it at the library level.
An alternative would however to use duck-typing. Instead of checking for datetime
instances, we could check for any instance having a callable timestamp()
method:
elif callable(getattr(mtime, 'timestamp', None)):
mtime = mtime.timestamp()
However, this would be again quite niche and could open other holes. What about other conversion methods? etc and perhaps we need more checks. So, considering this, I think it's fine to keep it as is.
What I may however think of is that we could have datetime
objects implement __int__
so that int(mtime)
would be int(mtime.timestamp())
for datetime
objects. But this is something orthogonal and I'm not sure that it makes sense (also should we assume UTC
timezone for that? or something else?)
Thus, I suggest closing this one unless @serhiy-storchaka thinks that the protocol check is fine and/or implementing __int__
for timestamp
conversion on datetime objects is a good idea.
Allows the
mtime
parameter ofgzip.GzipFile
andgzip.compress
to be adatetime.datetime
object.📚 Documentation preview 📚: https://cpython-previews--128589.org.readthedocs.build/