-
Notifications
You must be signed in to change notification settings - Fork 445
Remove unnecessary dependency on pytz #517
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
Conversation
dateutil (already a dependency) provides a UTC object, so there's no need for a pytz dependency. This also drops the use of datetime.utcnow in favor of the preferred datetime.now(some_tzinfo).
@@ -290,7 +290,7 @@ def verify_chain(self, cert_chain_str_list, cert_str): | |||
|
|||
def certificate_not_valid_yet(self, cert): | |||
starts_to_be_valid = dateutil.parser.parse(cert.get_notBefore()) | |||
now = pytz.UTC.localize(datetime.datetime.utcnow()) | |||
now = datetime.datetime.now(dateutil.tz.tzutc()) |
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.
If you ever want to pin python-dateutil>=2.7.0
, you can replace this with dateutil.tz.UTC
.
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 would probably use the already created instance than calling for new one (even though it is a singleton).
now = datetime.datetime.now(dateutil.tz.UTC)
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.
It's up to you, I went with tz.tzutc()
because for most libraries the additional benefit of using the pre-created instance is minimal compared to the cost of pinning a dependency (which can lead to conflicts with some applications that pin to a different version). It's a bit slower to call tz.tzutc()
, but I'm guessing that this function is never called in a tight loop, so 300ns doesn't make much difference either way:
In [3]: %timeit datetime.now(tz.UTC)
1.3 µs ± 7.18 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
In [4]: %timeit datetime.now(tz.tzutc())
1.65 µs ± 5.65 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
Codecov Report
@@ Coverage Diff @@
## master #517 +/- ##
==========================================
+ Coverage 65.17% 65.21% +0.03%
==========================================
Files 99 99
Lines 25671 25671
==========================================
+ Hits 16731 16741 +10
+ Misses 8940 8930 -10
Continue to review full report at Codecov.
|
Hello and thanks for this. I have already dropped both pytz and dateutil dependencies in the |
I can't say I love the heavy use of I'm obviously biased as the developer of Feel free to @ me for the PR review. |
By the way I don't mind if you close this because the datetime refactor is coming, but it's a minor enough change that also removes an unnecessary dependency, so if it were me I'd just merge it in the meantime in case you want to cut a new release before the datetime refactor is done. |
There are two things that we use from
(We also use it to define the UTC timezone; but this was done for brevity as it was already available, and is easily replaceable by the classes provided by the standard library.) The way the new module is written is such that it is not tied to a third party. The dependency should be easily swapped by filling in the required parsers; which should be as easy as changing the following two lines: Considering whether a library is light in the sense of it existing in a system; the trend nowadays is to use containers to deploy services. With containers the installed packages are not shared, but each container installs its own set. This means that packages are only shared between dependencies of services. But even without containers, The reason I chose
This does not go against |
Ah, some of these are good points, though just for the record
Specifically looking at I did not see where you needed support for durations, but I will admit that I haven't gotten around to doing that yet. The big problem with supporting durations is that the standard includes things like "months" and "years", which are not possible to represent as a |
I am closing this but will come back to it as needed. Thanks for the discussion; I will reconsider all your points and add a relative section warning for the limitations of |
dateutil
(already a dependency) provides aUTC
object, so there's no need for apytz
dependency.This also drops the use of
datetime.utcnow
in favor of the preferreddatetime.now(some_tzinfo)
, what is being done now is effectively the equivalent of:datetime.now(UTC).replace(tzinfo=None).replace(tzinfo=UTC)
.utcnow
is a relic from before thetz
argument was added todatetime.now
.All Submissions: